source: trip-planner-front/node_modules/core-js/modules/es.promise.all-settled.js

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

initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var aFunction = require('../internals/a-function');
4var newPromiseCapabilityModule = require('../internals/new-promise-capability');
5var perform = require('../internals/perform');
6var iterate = require('../internals/iterate');
7
8// `Promise.allSettled` method
9// https://tc39.es/ecma262/#sec-promise.allsettled
10$({ target: 'Promise', stat: true }, {
11 allSettled: function allSettled(iterable) {
12 var C = this;
13 var capability = newPromiseCapabilityModule.f(C);
14 var resolve = capability.resolve;
15 var reject = capability.reject;
16 var result = perform(function () {
17 var promiseResolve = aFunction(C.resolve);
18 var values = [];
19 var counter = 0;
20 var remaining = 1;
21 iterate(iterable, function (promise) {
22 var index = counter++;
23 var alreadyCalled = false;
24 values.push(undefined);
25 remaining++;
26 promiseResolve.call(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});
Note: See TracBrowser for help on using the repository browser.