sussudio
Version:
An unofficial VS Code Internal API
31 lines (30 loc) • 1.22 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { isThenable, Promises } from "../../../base/common/async.mjs";
// Shared veto handling across main and renderer
export function handleVetos(vetos, onError) {
if (vetos.length === 0) {
return Promise.resolve(false);
}
const promises = [];
let lazyValue = false;
for (const valueOrPromise of vetos) {
// veto, done
if (valueOrPromise === true) {
return Promise.resolve(true);
}
if (isThenable(valueOrPromise)) {
promises.push(valueOrPromise.then(value => {
if (value) {
lazyValue = true; // veto, done
}
}, err => {
onError(err); // error, treated like a veto, done
lazyValue = true;
}));
}
}
return Promises.settled(promises).then(() => lazyValue);
}