/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Deferred promise */ export class Deferred implements Promise { promise: Promise; resolve!: (value?: T | PromiseLike) => void; reject!: (reason?: any) => void; constructor() { this.promise = new Promise((resolve, reject) => { this.resolve = resolve; this.reject = reject; }); } then(onfulfilled?: (value: T) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; then(onFulfilled?: (value: T) => U | Thenable, onRejected?: (error: any) => U | Thenable): Promise; then(onFulfilled?: (value: T) => U | Thenable, onRejected?: (error: any) => void): Promise; then(onFulfilled?: any, onRejected?: any) { return this.promise.then(onFulfilled, onRejected); } catch(onrejected?: (reason: any) => TResult | PromiseLike): Promise; catch(onRejected?: (error: any) => U | Thenable): Promise; catch(onRejected?: any) { return this.promise.catch(onRejected); } finally(onfinally?: () => void): Promise { return this.promise.finally(onfinally); } get [Symbol.toStringTag](): string { return this.promise[Symbol.toStringTag]; // symbol tag same as that of underlying promise object } }