source: trip-planner-front/node_modules/core-js/modules/es.promise.any.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var aFunction = require('../internals/a-function');
4var getBuiltIn = require('../internals/get-built-in');
5var newPromiseCapabilityModule = require('../internals/new-promise-capability');
6var perform = require('../internals/perform');
7var iterate = require('../internals/iterate');
8
9var PROMISE_ANY_ERROR = 'No one promise resolved';
10
11// `Promise.any` method
12// https://tc39.es/ecma262/#sec-promise.any
13$({ target: 'Promise', stat: true }, {
14 any: function any(iterable) {
15 var C = this;
16 var capability = newPromiseCapabilityModule.f(C);
17 var resolve = capability.resolve;
18 var reject = capability.reject;
19 var result = perform(function () {
20 var promiseResolve = aFunction(C.resolve);
21 var errors = [];
22 var counter = 0;
23 var remaining = 1;
24 var alreadyResolved = false;
25 iterate(iterable, function (promise) {
26 var index = counter++;
27 var alreadyRejected = false;
28 errors.push(undefined);
29 remaining++;
30 promiseResolve.call(C, promise).then(function (value) {
31 if (alreadyRejected || alreadyResolved) return;
32 alreadyResolved = true;
33 resolve(value);
34 }, function (error) {
35 if (alreadyRejected || alreadyResolved) return;
36 alreadyRejected = true;
37 errors[index] = error;
38 --remaining || reject(new (getBuiltIn('AggregateError'))(errors, PROMISE_ANY_ERROR));
39 });
40 });
41 --remaining || reject(new (getBuiltIn('AggregateError'))(errors, PROMISE_ANY_ERROR));
42 });
43 if (result.error) reject(result.value);
44 return capability.promise;
45 }
46});
Note: See TracBrowser for help on using the repository browser.