Skip to content

Instantly share code, notes, and snippets.

@ccnokes
Last active March 23, 2018 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccnokes/d133a56f7be0208658c2610eb6044715 to your computer and use it in GitHub Desktop.
Save ccnokes/d133a56f7be0208658c2610eb6044715 to your computer and use it in GitHub Desktop.
AngularJS $q style deferred from a native Promise, in TypeScript
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