mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2024-12-22 19:13:49 +01:00
fix throttle
This commit is contained in:
parent
7fe47b78ca
commit
73764aed75
@ -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;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user