Skip to content

Instantly share code, notes, and snippets.

@andrejewski
Created November 19, 2016 15:32
Show Gist options
  • Save andrejewski/2289df04703f97e9d0ee21ca89eccd5c to your computer and use it in GitHub Desktop.
Save andrejewski/2289df04703f97e9d0ee21ca89eccd5c to your computer and use it in GitHub Desktop.
My quick deferred utility I seem to use everywhere
/*
Defer.js
Usage:
const myDefer = new Defer()
myDefer.then(x => assert.equal(x, 1))
myDefer.resolve(1)
*/
export default class Defer {
constructor () {
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve
this.reject = reject
})
}
then (...args) {
return this.promise.then(...args)
}
catch (...args) {
return this.promise.catch(...args)
}
finally (...args) {
return this.promise.finally(...args)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment