Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 1x 1x 5x 5x 5x | /** * An externally resolvable/rejectable "promise". Use it to resolve/reject * promise at any time. * * ```ts * const future = new Defer(); * * future.promise.then(value => console.log(value)); * * future.resolve(123); * ``` */ export class Defer<T> { public readonly resolve!: (data: T) => void; public readonly reject!: (error: any) => void; public readonly promise: Promise<T> = new Promise<T>((resolve, reject) => { (this as any).resolve = resolve; (this as any).reject = reject; }); } |