Created
April 25, 2019 15:09
-
-
Save dcrystalj/8ed3d182b3bedab3fd0f0388e7ab5665 to your computer and use it in GitHub Desktop.
simple promise queue framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const PromiseQueue = function() { | |
let defered = Promise.resolve(); | |
return { | |
push(fn) { | |
defered = defered.then(fn, fn); | |
return this; | |
} | |
}; | |
}; | |
export const waitOnQueue = function(fn, time = 100) { | |
return function() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
requestAnimationFrame(() => { | |
fn(); | |
resolve(); | |
}); | |
}, time); | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
idea copied from http://erictrinh.com/posts/promise-queues/