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.
26 lines
1.0 KiB
26 lines
1.0 KiB
'use strict'; |
|
var $ = require('../internals/export'); |
|
var call = require('../internals/function-call'); |
|
var aCallable = require('../internals/a-callable'); |
|
var newPromiseCapabilityModule = require('../internals/new-promise-capability'); |
|
var perform = require('../internals/perform'); |
|
var iterate = require('../internals/iterate'); |
|
var PROMISE_STATICS_INCORRECT_ITERATION = require('../internals/promise-statics-incorrect-iteration'); |
|
|
|
// `Promise.race` method |
|
// https://tc39.es/ecma262/#sec-promise.race |
|
$({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION }, { |
|
race: function race(iterable) { |
|
var C = this; |
|
var capability = newPromiseCapabilityModule.f(C); |
|
var reject = capability.reject; |
|
var result = perform(function () { |
|
var $promiseResolve = aCallable(C.resolve); |
|
iterate(iterable, function (promise) { |
|
call($promiseResolve, C, promise).then(capability.resolve, reject); |
|
}); |
|
}); |
|
if (result.error) reject(result.value); |
|
return capability.promise; |
|
} |
|
});
|
|
|