mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 21:39:43 +00:00
more TS 4.1 fixes (#106358)
This commit is contained in:
parent
41794e5631
commit
72f468f569
|
@ -52,21 +52,21 @@ export function createCancelablePromise<T>(callback: (token: CancellationToken)
|
|||
|
||||
export function raceCancellation<T>(promise: Promise<T>, token: CancellationToken): Promise<T | undefined>;
|
||||
export function raceCancellation<T>(promise: Promise<T>, token: CancellationToken, defaultValue: T): Promise<T>;
|
||||
export function raceCancellation<T>(promise: Promise<T>, token: CancellationToken, defaultValue?: T): Promise<T> {
|
||||
return Promise.race([promise, new Promise<T>(resolve => token.onCancellationRequested(() => resolve(defaultValue)))]);
|
||||
export function raceCancellation<T>(promise: Promise<T>, token: CancellationToken, defaultValue?: T): Promise<T | undefined> {
|
||||
return Promise.race([promise, new Promise<T | undefined>(resolve => token.onCancellationRequested(() => resolve(defaultValue)))]);
|
||||
}
|
||||
|
||||
export function raceTimeout<T>(promise: Promise<T>, timeout: number, onTimeout?: () => void): Promise<T> {
|
||||
let promiseResolve: (() => void) | undefined = undefined;
|
||||
export function raceTimeout<T>(promise: Promise<T>, timeout: number, onTimeout?: () => void): Promise<T | undefined> {
|
||||
let promiseResolve: ((value: T | undefined) => void) | undefined = undefined;
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
promiseResolve?.();
|
||||
promiseResolve?.(undefined);
|
||||
onTimeout?.();
|
||||
}, timeout);
|
||||
|
||||
return Promise.race([
|
||||
promise.finally(() => clearTimeout(timer)),
|
||||
new Promise<T>(resolve => promiseResolve = resolve)
|
||||
new Promise<T | undefined>(resolve => promiseResolve = resolve)
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue