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;
// }
export function createThrottle() {
function createThrottle() {
let next = null;
return callback => {
const startLoop = next === null;
next = callback;
if (!startLoop) return;
if (!startLoop) return null;
return (function loop() {
return next().then(() => {
return function loop() {
const promise = next().then(() => {
if (typeof next === 'function') return loop();
});
next = true;
})().then(() => {
return promise;
}().then(() => {
next = null;
});
};