1"use strict"; 2/* 3Copyright 2022 The Sigstore Authors. 4 5Licensed under the Apache License, Version 2.0 (the "License"); 6you may not use this file except in compliance with the License. 7You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11Unless required by applicable law or agreed to in writing, software 12distributed under the License is distributed on an "AS IS" BASIS, 13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14See the License for the specific language governing permissions and 15limitations under the License. 16*/ 17Object.defineProperty(exports, "__esModule", { value: true }); 18exports.promiseAny = void 0; 19// Implementation of Promise.any (not available until Node v15). 20// We're basically inverting the logic of Promise.all and taking advantage 21// of the fact that Promise.all will return early on the first rejection. 22// By reversing the resolve/reject logic we can use this to return early 23// on the first resolved promise. 24const promiseAny = async (values) => { 25 return Promise.all([...values].map((promise) => new Promise((resolve, reject) => promise.then(reject, resolve)))).then((errors) => Promise.reject(errors), (value) => Promise.resolve(value)); 26}; 27exports.promiseAny = promiseAny; 28