Skip to content

Instantly share code, notes, and snippets.

@shanewholloway
Created October 31, 2017 16:21
Show Gist options
  • Save shanewholloway/65e1e1b0e7ba76a4c466d35607667693 to your computer and use it in GitHub Desktop.
Save shanewholloway/65e1e1b0e7ba76a4c466d35607667693 to your computer and use it in GitHub Desktop.
Promise Queue pattern as alternative for setImmediate/nextTick
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