Archived
1
0

Update to VS Code 1.52.1

This commit is contained in:
Asher
2021-02-09 16:08:37 +00:00
1351 changed files with 56560 additions and 38990 deletions

View File

@ -445,6 +445,45 @@ export function first<T>(promiseFactories: ITask<Promise<T>>[], shouldStop: (t:
return loop();
}
/**
* Returns the result of the first promise that matches the "shouldStop",
* running all promises in parallel. Supports cancelable promises.
*/
export function firstParallel<T>(promiseList: Promise<T>[], shouldStop?: (t: T) => boolean, defaultValue?: T | null): Promise<T | null>;
export function firstParallel<T, R extends T>(promiseList: Promise<T>[], shouldStop: (t: T) => t is R, defaultValue?: R | null): Promise<R | null>;
export function firstParallel<T>(promiseList: Promise<T>[], shouldStop: (t: T) => boolean = t => !!t, defaultValue: T | null = null) {
if (promiseList.length === 0) {
return Promise.resolve(defaultValue);
}
let todo = promiseList.length;
const finish = () => {
todo = -1;
for (const promise of promiseList) {
(promise as Partial<CancelablePromise<T>>).cancel?.();
}
};
return new Promise<T | null>((resolve, reject) => {
for (const promise of promiseList) {
promise.then(result => {
if (--todo >= 0 && shouldStop(result)) {
finish();
resolve(result);
} else if (todo === 0) {
resolve(defaultValue);
}
})
.catch(err => {
if (--todo >= 0) {
finish();
reject(err);
}
});
}
});
}
interface ILimitedTaskFactory<T> {
factory: ITask<Promise<T>>;
c: (value: T | Promise<T>) => void;