Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

es.promise.all-settled.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var call = require('../internals/function-call');
  4. var aCallable = require('../internals/a-callable');
  5. var newPromiseCapabilityModule = require('../internals/new-promise-capability');
  6. var perform = require('../internals/perform');
  7. var iterate = require('../internals/iterate');
  8. var PROMISE_STATICS_INCORRECT_ITERATION = require('../internals/promise-statics-incorrect-iteration');
  9. // `Promise.allSettled` method
  10. // https://tc39.es/ecma262/#sec-promise.allsettled
  11. $({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION }, {
  12. allSettled: function allSettled(iterable) {
  13. var C = this;
  14. var capability = newPromiseCapabilityModule.f(C);
  15. var resolve = capability.resolve;
  16. var reject = capability.reject;
  17. var result = perform(function () {
  18. var promiseResolve = aCallable(C.resolve);
  19. var values = [];
  20. var counter = 0;
  21. var remaining = 1;
  22. iterate(iterable, function (promise) {
  23. var index = counter++;
  24. var alreadyCalled = false;
  25. remaining++;
  26. call(promiseResolve, C, promise).then(function (value) {
  27. if (alreadyCalled) return;
  28. alreadyCalled = true;
  29. values[index] = { status: 'fulfilled', value: value };
  30. --remaining || resolve(values);
  31. }, function (error) {
  32. if (alreadyCalled) return;
  33. alreadyCalled = true;
  34. values[index] = { status: 'rejected', reason: error };
  35. --remaining || resolve(values);
  36. });
  37. });
  38. --remaining || resolve(values);
  39. });
  40. if (result.error) reject(result.value);
  41. return capability.promise;
  42. }
  43. });