From 73764aed752d6f419cd4ae772429c7cd29c95140 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Wed, 8 Nov 2017 23:34:54 +0100 Subject: [PATCH] fix throttle --- src/utils/async.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utils/async.js b/src/utils/async.js index bb107f3..0af481d 100644 --- a/src/utils/async.js +++ b/src/utils/async.js @@ -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; }); };