Files
2026-02-05 15:27:49 +08:00

19 lines
577 B
JavaScript

/**
* Call the functions in the array one by one and return the result of the first one that doesn't throw an error.
*
* If all functions throw an error, throw the error of the last function.
*/
export function getFirstValidResult(options) {
for (let i = 0; i < options.length; i++) {
if (i === options.length - 1)
return options[i]();
try {
return options[i]();
}
catch (err) {
// do nothing
}
}
throw new Error("All options failed");
}
//# sourceMappingURL=getFirstValidResult.js.map