promiseHelpers.js 831 B

123456789101112131415161718192021222324
  1. const Promise = require('bluebird')
  2. /**
  3. * Creates a promise that is resolved when all input promises have been
  4. * settled. The returned Promise is resolved with an array of
  5. * Promise.Inspection objects.
  6. *
  7. * This is the commonly accepted way of implementing allSettled() in Bluebird.
  8. * See: http://bluebirdjs.com/docs/api/reflect.html
  9. *
  10. * @param promises - The array of input promises.
  11. * @returns {Promise<Promise.Inspection[]>} A promise that will be resolved once
  12. * all input Promises have settled. The returned Promise will be resolved with a
  13. * corresponding array of Promise.Inspection objects.
  14. */
  15. function allSettled(promises) {
  16. 'use strict'
  17. const wrappedPromises = promises.map((curPromise) => curPromise.reflect())
  18. return Promise.all(wrappedPromises)
  19. }
  20. module.exports = {
  21. allSettled: allSettled
  22. }