@sussudio/platform
Version:
Internal APIs for VS Code's service injection the base services.
36 lines (35 loc) • 1.11 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 '@sussudio/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);
}