Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/lifecycle/common/lifecycle.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { isThenable, Promises } from '../../../base/common/async.js';
7
8
// Shared veto handling across main and renderer
9
export function handleVetos(vetos: (boolean | Promise<boolean>)[], onError: (error: Error) => void): Promise<boolean /* veto */> {
10
if (vetos.length === 0) {
11
return Promise.resolve(false);
12
}
13
14
const promises: Promise<void>[] = [];
15
let lazyValue = false;
16
17
for (const valueOrPromise of vetos) {
18
19
// veto, done
20
if (valueOrPromise === true) {
21
return Promise.resolve(true);
22
}
23
24
if (isThenable(valueOrPromise)) {
25
promises.push(valueOrPromise.then(value => {
26
if (value) {
27
lazyValue = true; // veto, done
28
}
29
}, err => {
30
onError(err); // error, treated like a veto, done
31
lazyValue = true;
32
}));
33
}
34
}
35
36
return Promises.settled(promises).then(() => lazyValue);
37
}
38
39