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.race.js 1.0KB

1234567891011121314151617181920212223242526
  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.race` method
  10. // https://tc39.es/ecma262/#sec-promise.race
  11. $({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION }, {
  12. race: function race(iterable) {
  13. var C = this;
  14. var capability = newPromiseCapabilityModule.f(C);
  15. var reject = capability.reject;
  16. var result = perform(function () {
  17. var $promiseResolve = aCallable(C.resolve);
  18. iterate(iterable, function (promise) {
  19. call($promiseResolve, C, promise).then(capability.resolve, reject);
  20. });
  21. });
  22. if (result.error) reject(result.value);
  23. return capability.promise;
  24. }
  25. });