Last active
March 23, 2018 19:28
-
-
Save ccnokes/d133a56f7be0208658c2610eb6044715 to your computer and use it in GitHub Desktop.
AngularJS $q style deferred from a native Promise, in TypeScript
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
class Deferred<T = any> { | |
resolve: (value?: T | PromiseLike<T>) => void; | |
reject: (reason?: any) => void; | |
promise = new Promise<T>((resolve, reject) => { | |
this.resolve = resolve; | |
this.reject = reject; | |
}); | |
then = this.promise.then.bind(this.promise); | |
catch = this.promise.catch.bind(this.promise); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment