Last active
February 12, 2026 21:56
-
-
Save SystemDisc/80854e40b2ef9b50a0158757daed9bf6 to your computer and use it in GitHub Desktop.
class definition for DeferredPromise
This file contains hidden or 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
| export class DeferredPromise<T> { | |
| public promise: Promise<T>; | |
| private resolved: PromiseLike<T>; | |
| public constructor() { | |
| this.promise = new Promise((resolve, reject) => { | |
| if (this.resolved) { | |
| resolve(this.resolved); | |
| } | |
| this.resolve = resolve; | |
| this.reject = reject; | |
| }); | |
| } | |
| public resolve(value?: T | PromiseLike<T>) { | |
| if (!this.resolved) { | |
| this.resolved = Promise.resolve(value); | |
| } | |
| } | |
| public reject(reason?: any) { | |
| if (!this.resolved) { | |
| this.resolved = Promise.reject(reason); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment