Skip to content

Instantly share code, notes, and snippets.

@tokenvolt
Created October 22, 2017 00:34
Show Gist options
  • Save tokenvolt/7c34f87a6551870cab81332fcf123dbc to your computer and use it in GitHub Desktop.
Save tokenvolt/7c34f87a6551870cab81332fcf123dbc to your computer and use it in GitHub Desktop.
Example of resetted promise
function asyncMessage(msg) {
let deferred
const onMessage = function (msg) {
if (deferred) {
deferred.resolve(msg)
deferred = null
}
}
const nextMessage = function () {
if (!deferred) {
deferred = {}
deferred.promise = new Promise(resolve => deferred.resolve = resolve)
}
return deferred.promise
}
setTimeout(() => onMessage(msg), 3000)
return nextFrame
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment