Skip to content

Instantly share code, notes, and snippets.

@sungchuni
Last active January 8, 2023 14:02
Show Gist options
  • Save sungchuni/137ecd2fa2b38ba9ef89a64925124f68 to your computer and use it in GitHub Desktop.
Save sungchuni/137ecd2fa2b38ba9ef89a64925124f68 to your computer and use it in GitHub Desktop.
use deferreds
class Defer {
constructor() {
this.promise = new Promise((resolve, reject) =>
Object.assign(this, {resolve, reject})
);
}
}
export class Defer<T> {
promise: Promise<T>;
resolve: (value: T | PromiseLike<T>) => void = () => {};
reject: (reason?: unknown) => void = () => {};
constructor() {
this.promise = new Promise<T>((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment