/** * Wrapper class for promise with external resolve and reject. */ export class Deferred { /** * The promise associated with this deferred object. */ public readonly promise: Promise; private _resolve: (value: T | PromiseLike) => void; private _reject: (reason?: any) => void; /** * The resolve method of the promise associated with this deferred object. */ public get resolve() { return this._resolve; } /** * The reject method of the promise associated with this deferred object. */ public get reject() { return this._reject; } /** * Constructor for this deferred object. */ constructor() { this.promise = new Promise((resolve: (value: T | PromiseLike) => void, reject) => { this._resolve = resolve; this._reject = reject; }); } }