Skip to content

Instantly share code, notes, and snippets.

@fed135
Created June 22, 2021 13:11
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 fed135/3338b3a8bbecb7487bf376036849598e to your computer and use it in GitHub Desktop.
Save fed135/3338b3a8bbecb7487bf376036849598e to your computer and use it in GitHub Desktop.
Deferred Promise
export function deferred<T>() {
let resolve: (value?: T | PromiseLike<T>) => void;
let reject: (reason?: any) => void;
const promise = new Promise<T>((res, rej) => {
resolve = res;
reject = rej;
});
return { promise, resolve, reject };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment