src/utils/promise.js
/**
 * Returns a promise which resolves if a threshold amount of the given promises
 * resolve, and rejects otherwise.
 * @param {!Array<!Promise>} promises The array of promises to test.
 * @param {number} count The number of promises that must resolve for the
 *     returned promise to resolve.
 * @return {!Promise} A promise that resolves if any of the given promises
 *     resolve, and which rejects otherwise.
 */
Returns a promise which resolves if a threshold amount of the given promises
resolve, and rejects otherwise.
@param {!Array} promises The array of promises to test.
@param {number} count The number of promises that must resolve for the
returned promise to resolve.
@return {!Promise} A promise that resolves if any of the given promises
resolve, and which rejects otherwise.
Returns a promise which resolves if a threshold amount of the given promises resolve and rejects otherwise . @param { !Array } promises The array of promises to test . @param { number } count The number of promises that must resolve for the returned promise to resolve . @return { !Promise } A promise that resolves if any of the given promises resolve and which rejects otherwise .
function some(promises, count = 1) {
  return new Promise((resolve, reject) => {
    count = Math.max(count, 0);
    const extra = promises.length - count;
    if (extra < 0) {
      reject(new Error('not enough promises to resolve'));
    }
    if (promises.length == 0) {
      resolve([]);
    }
    const values = [];
    const reasons = [];
    const onFulfilled = value => {
      if (values.length < count) {
        values.push(value);
      }
      if (values.length == count) {
        resolve(values);
      }
    };
    const onRejected = reason => {
      if (reasons.length <= extra) {
        reasons.push(reason);
      }
      if (reasons.length > extra) {
        reject(reasons);
      }
    };
    for (let i = 0; i < promises.length; i++) {
      Promise.resolve(promises[i]).then(onFulfilled, onRejected);
    }
  });
}
function some ( promises , count = 1 ) { return new Promise ( ( resolve , reject ) => { count = Math . max ( count , 0 ) ; const extra = promises . length - count ; if ( extra < 0 ) { reject ( new Error ( 'not enough promises to resolve' ) ) ; } if ( promises . length == 0 ) { resolve ( [ ] ) ; } const values = [ ] ; const reasons = [ ] ; const onFulfilled = value => { if ( values . length < count ) { values . push ( value ) ; } if ( values . length == count ) { resolve ( values ) ; } } ; const onRejected = reason => { if ( reasons . length <= extra ) { reasons . push ( reason ) ; } if ( reasons . length > extra ) { reject ( reasons ) ; } } ; for ( let i = 0 ; i < promises . length ; i ++ ) { Promise . resolve ( promises [ i ] ) . then ( onFulfilled , onRejected ) ; } } ) ; }
Returns a promise which resolves if a threshold amount of the given promises
 resolve, and rejects otherwise.
Returns a promise which resolves if a threshold amount of the given promises resolve and rejects otherwise .