Created
November 19, 2016 15:32
-
-
Save andrejewski/2289df04703f97e9d0ee21ca89eccd5c to your computer and use it in GitHub Desktop.
My quick deferred utility I seem to use everywhere
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
/* | |
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