"use strict";
// type ResolveCallback<T> = (value?: T | PromiseLike<T>) => void;
// type RejectCallback = (reason?: any) => any;
// type ThenCallback<T, T2 = T> = (value: T) => T2;
// type CatchCallback<T> = (value: any) => T;
// type ExecutorType<T> = (resolve: ResolveCallback<T>, reject: RejectCallback) => void;
// function handleCallback<T>(resolve: ResolveCallback<T>, reject: RejectCallback, callback: (value: any) => T, result: T) {
//     try {
//         resolve(callback(result));
//     } catch (e) {
//         reject(e);
//     }
// };
// export class CancelablePromise<T> {
//     private _canceled: boolean;
//     _promise: Promise<any>;
//     public static all(iterable: Promise<any>[]) {
//         return new CancelablePromise((y, n) => {
//             Promise.all(iterable).then(y, n);
//         });
//     }
//     public static race(iterable: Promise<any>[]) {
//         return new CancelablePromise((y, n) => {
//             Promise.race(iterable).then(y, n);
//         });
//     }
//     public static reject(value: Promise<any>) {
//         return new CancelablePromise((y, n) => {
//             Promise.reject(value).then(y, n);
//         });
//     }
//     public static resolve<T>(value: Promise<T>) {
//         return new CancelablePromise((y, n) => {
//             Promise.resolve(value).then(y, n);
//         });
//     }
//     constructor(executor: ExecutorType<T>) {
//         this._promise = new Promise<T>(executor);
//         this._canceled = false;
//     }
//     public then<T2 = T>(success?: ThenCallback<T, T2>, error?: RejectCallback) : CancelablePromise<T2>{
//         const p = new CancelablePromise<T2>((resolve, reject) => {
//             this._promise.then((result: T2) => {
//                 if (this._canceled) {
//                     p.cancel();
//                 }
//                 if (success && !this._canceled) {
//                     handleCallback<T2>(resolve, reject, success, result);
//                 } else {
//                     resolve(result);
//                 }
//             }, (r: Error) => {
//                 if (this._canceled) {
//                     p.cancel();
//                 }
//                 if (error && !this._canceled) {
//                     handleCallback(resolve, reject, error, r);
//                 } else {
//                     reject(r);
//                 }
//             });
//         });
//         return p;
//     }
//     public catch(callback?: RejectCallback) {
//         return this.then(undefined, callback);
//     }
//     public  cancel(errorCallback?: RejectCallback) {
//         this._canceled = true;
//         if (errorCallback) {
//             this._promise.catch(errorCallback);
//         }
//         return this;
//     }
// }
