fix throttle

This commit is contained in:
casperlamboo 2017-11-08 23:34:54 +01:00
parent 7fe47b78ca
commit 73764aed75

View File

@ -43,21 +43,22 @@ export function asyncIterator(array, callback) {
// return result; // return result;
// } // }
export function createThrottle() { function createThrottle() {
let next = null; let next = null;
return callback => { return callback => {
const startLoop = next === null; const startLoop = next === null;
next = callback; next = callback;
if (!startLoop) return; if (!startLoop) return null;
return (function loop() { return function loop() {
return next().then(() => { const promise = next().then(() => {
if (typeof next === 'function') return loop(); if (typeof next === 'function') return loop();
}); });
next = true; next = true;
})().then(() => { return promise;
}().then(() => {
next = null; next = null;
}); });
}; };