Ramda Adjunct 2.30.0

allSettledP.js

  1. import { bind, curryN } from 'ramda';
  2. import isFunction from './isFunction';
  3. import ponyfill from './internal/ponyfills/Promise.allSettled';
  4. export const allSettledPPonyfill = curryN(1, ponyfill);
  5. /**
  6. * Returns a promise that is fulfilled with an array of promise state snapshots,
  7. * but only after all the original promises have settled, i.e. become either fulfilled or rejected.
  8. * We say that a promise is settled if it is not pending, i.e. if it is either fulfilled or rejected.
  9. *
  10. * @func allSettledP
  11. * @memberOf RA
  12. * @since {@link https://char0n.github.io/ramda-adjunct/2.18.0|v2.18.0}
  13. * @category Function
  14. * @typedef Settlement = { status: String, value: * }
  15. * @sig [Promise a] -> Promise [Settlement a]
  16. * @param {Iterable.<*>} iterable An iterable object such as an Array or String
  17. * @return {Promise} Returns a promise that is fulfilled with an array of promise state snapshots
  18. * @see {@link RA.allP|allP}
  19. * @example
  20. *
  21. * RA.allSettledP([
  22. * Promise.resolve(1),
  23. * 2,
  24. * Promise.reject(3),
  25. * ]); //=> Promise([{ status: 'fulfilled', value: 1 }, { status: 'fulfilled', value: 2 }, { status: 'rejected', reason: 3 }])
  26. */
  27. const allSettledP = isFunction(Promise.allSettled)
  28. ? curryN(1, bind(Promise.allSettled, Promise))
  29. : allSettledPPonyfill;
  30. export default allSettledP;