Created
October 31, 2017 16:21
-
-
Save shanewholloway/65e1e1b0e7ba76a4c466d35607667693 to your computer and use it in GitHub Desktop.
Promise Queue pattern as alternative for setImmediate/nextTick
This file contains hidden or 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
function promiseQueue(nextPromise=() => Promise.resolve()) { | |
let tip = null | |
return function () { | |
if (null === tip) { | |
tip = nextPromise() | |
tip.then(clear_tip) } | |
return tip | |
} | |
function clear_tip() { tip = null } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment