debt - remove TPromise.any and use Promise.race instead
This commit is contained in:
parent
0b9efda561
commit
06fe5c4f8b
5 changed files with 11 additions and 8 deletions
2
src/vs/base/common/winjs.base.d.ts
vendored
2
src/vs/base/common/winjs.base.d.ts
vendored
|
@ -23,8 +23,6 @@ export class Promise<T = any> {
|
|||
public static join<T1, T2>(promises: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
|
||||
public static join<T>(promises: (T | PromiseLike<T>)[]): Promise<T[]>;
|
||||
|
||||
public static any<T>(promises: (T | PromiseLike<T>)[]): Promise<{ key: string; value: Promise<T>; }>;
|
||||
|
||||
public static wrap<T>(value: T | PromiseLike<T>): Promise<T>;
|
||||
|
||||
public static wrapError<T = never>(error: Error): Promise<T>;
|
||||
|
|
|
@ -11,6 +11,10 @@ function isWinJSPromise(candidate: any): candidate is WinJSPromise {
|
|||
return isThenable(candidate) && typeof (candidate as any).done === 'function';
|
||||
}
|
||||
|
||||
declare class WinJSPromiseRemovals {
|
||||
any<T=any>(promises: (T | PromiseLike<T>)[]): WinJSPromise<{ key: string; value: WinJSPromise<T>; }>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A polyfill for the native promises. The implementation is based on
|
||||
* WinJS promises but tries to gap differences between winjs promises
|
||||
|
@ -33,7 +37,7 @@ export class PolyfillPromise<T = any> implements Promise<T> {
|
|||
static race(thenables: Thenable<any>[]): PolyfillPromise {
|
||||
// WinJSPromise returns `{ key: <index/key>, value: <promise> }`
|
||||
// from the `any` call and Promise.race just wants the value
|
||||
return new PolyfillPromise(WinJSPromise.any(thenables).then(entry => entry.value, err => err.value));
|
||||
return new PolyfillPromise((WinJSPromise as any as WinJSPromiseRemovals).any(thenables).then(entry => entry.value, err => err.value));
|
||||
}
|
||||
|
||||
static resolve(value): PolyfillPromise {
|
||||
|
|
2
src/vs/monaco.d.ts
vendored
2
src/vs/monaco.d.ts
vendored
|
@ -55,8 +55,6 @@ declare namespace monaco {
|
|||
public static join<T1, T2>(promises: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
|
||||
public static join<T>(promises: (T | PromiseLike<T>)[]): Promise<T[]>;
|
||||
|
||||
public static any<T>(promises: (T | PromiseLike<T>)[]): Promise<{ key: string; value: Promise<T>; }>;
|
||||
|
||||
public static wrap<T>(value: T | PromiseLike<T>): Promise<T>;
|
||||
|
||||
public static wrapError<T = never>(error: Error): Promise<T>;
|
||||
|
|
|
@ -232,7 +232,7 @@ export class LaunchService implements ILaunchService {
|
|||
// is being used and only then resolve the startup promise which will kill this second instance.
|
||||
// In addition, we poll for the wait marker file to be deleted to return.
|
||||
if (args.wait && usedWindows.length === 1 && usedWindows[0]) {
|
||||
return TPromise.any([
|
||||
return Promise.race([
|
||||
this.windowsMainService.waitForWindowCloseOrLoad(usedWindows[0].id),
|
||||
whenDeleted(args.waitMarkerFilePath)
|
||||
]).then(() => void 0, () => void 0);
|
||||
|
|
|
@ -53,8 +53,11 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
|
|||
canPickMany: options && options.canPickMany
|
||||
}, token);
|
||||
|
||||
return TPromise.any(<TPromise<number | Item[]>[]>[quickPickWidget, itemsPromise]).then(values => {
|
||||
if (values.key === '0') {
|
||||
const widgetClosedMarker = {};
|
||||
const widgetClosedPromise = quickPickWidget.then(() => widgetClosedMarker);
|
||||
|
||||
return Promise.race([widgetClosedPromise, itemsPromise]).then(result => {
|
||||
if (result === widgetClosedMarker) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue