Created
February 28, 2018 08:50
-
-
Save vldvel/1f15993b8fd0c0a1c59cea719a051d9a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function * throttle(func, time) { | |
let timerID = null; | |
function throttled(arg) { | |
clearTimeout(timerID); | |
timerID = setTimeout(func.bind(window, arg), time); | |
} | |
while (true) | |
throttled(yield); | |
} | |
const thr = throttle(console.log, 1000); | |
thr.next(); // {value: undefined, done: false} | |
thr.next('hello'); // {value: undefined, done: false} + 1s after -> 'hello' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment