mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2025-01-03 08:33:48 +01:00
add throttle function
This commit is contained in:
parent
e93a497cd8
commit
8eb1e4e7d0
@ -42,3 +42,42 @@ export function asyncIterator(array, callback) {
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
export function createThrottle() {
|
||||
let next = null;
|
||||
|
||||
return callback => {
|
||||
const startLoop = next === null;
|
||||
next = callback;
|
||||
|
||||
if (!startLoop) return;
|
||||
|
||||
return (function loop() {
|
||||
return next().then(() => {
|
||||
if (typeof next === 'function') return loop();
|
||||
});
|
||||
next = true;
|
||||
})();
|
||||
|
||||
next = null;
|
||||
};
|
||||
}
|
||||
|
||||
// export function createThrottle() {
|
||||
// let next = null;
|
||||
//
|
||||
// return async callback => {
|
||||
// const startLoop = next === null;
|
||||
// next = callback;
|
||||
//
|
||||
// if (!startLoop) return;
|
||||
//
|
||||
// while (typeof next === 'function') {
|
||||
// callback = next;
|
||||
// next = true;
|
||||
// await callback();
|
||||
// }
|
||||
//
|
||||
// next = null;
|
||||
// };
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user