-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
implementation.js
37 lines (32 loc) · 1.01 KB
/
implementation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
var requirePromise = require('./requirePromise');
requirePromise();
var PromiseResolve = require('es-abstract/2023/PromiseResolve');
var Type = require('es-abstract/2023/Type');
var iterate = require('iterate-value');
var map = require('array.prototype.map');
var GetIntrinsic = require('get-intrinsic');
var callBind = require('call-bind');
var all = callBind(GetIntrinsic('%Promise.all%'));
var reject = callBind(GetIntrinsic('%Promise.reject%'));
module.exports = function allSettled(iterable) {
var C = this;
if (Type(C) !== 'Object') {
throw new TypeError('`this` value must be an object');
}
var values = iterate(iterable);
return all(C, map(values, function (item) {
var onFulfill = function (value) {
return { status: 'fulfilled', value: value };
};
var onReject = function (reason) {
return { status: 'rejected', reason: reason };
};
var itemPromise = PromiseResolve(C, item);
try {
return itemPromise.then(onFulfill, onReject);
} catch (e) {
return reject(C, e);
}
}));
};