mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 13:43:07 +00:00
more TS 4.1 fixes (#106358)
This commit is contained in:
parent
41794e5631
commit
72f468f569
1 changed files with 6 additions and 6 deletions
|
@ -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): 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>;
|
||||||
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 | undefined> {
|
||||||
return Promise.race([promise, new Promise<T>(resolve => token.onCancellationRequested(() => resolve(defaultValue)))]);
|
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> {
|
export function raceTimeout<T>(promise: Promise<T>, timeout: number, onTimeout?: () => void): Promise<T | undefined> {
|
||||||
let promiseResolve: (() => void) | undefined = undefined;
|
let promiseResolve: ((value: T | undefined) => void) | undefined = undefined;
|
||||||
|
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
promiseResolve?.();
|
promiseResolve?.(undefined);
|
||||||
onTimeout?.();
|
onTimeout?.();
|
||||||
}, timeout);
|
}, timeout);
|
||||||
|
|
||||||
return Promise.race([
|
return Promise.race([
|
||||||
promise.finally(() => clearTimeout(timer)),
|
promise.finally(() => clearTimeout(timer)),
|
||||||
new Promise<T>(resolve => promiseResolve = resolve)
|
new Promise<T | undefined>(resolve => promiseResolve = resolve)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue