Promise.any()
accepts an iterable of promises and returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError
holding the rejection reasons if all of the given promises are rejected.
Well-known intrinsics are built-in objects that are explicitly referenced by the algorithms of this specification and which usually have
Within this specification a reference such as %name% means the intrinsic object, associated with the current
Intrinsic Name | Global Name | ECMAScript Language Association |
---|---|---|
|
AggregateError
|
The AggregateError |
%AggregateErrorPrototype% |
AggregateError.prototype
|
The initial value of the prototype |
Instances of Error objects are thrown as exceptions when runtime errors occur. The Error objects may also serve as base objects for user-defined exception classes.
When an ECMAScript implementation detects a runtime error, it throws a new instance of one of the NativeError objects defined in name
property of the prototype object, in the implementation-defined message
property of the prototype object, and in the presence of the errors
property.
Error instances are ordinary objects that inherit properties from the Error prototype object and have an [[ErrorData]] internal slot whose value is Object.prototype.toString
.
A new instance of one of the NativeError objects below or of the AggregateError object is thrown when a runtime error is detected. All of these objects share the same structure, as described in
For each error object, references to NativeError in the definition should be replaced with the appropriate error object name from
NativeError instances are ordinary objects that inherit properties from their NativeError prototype object and have an [[ErrorData]] internal slot whose value is Object.prototype.toString
(
The AggregateError
AggregateError
property of the AggregateError(…)
is equivalent to the object creation expression new AggregateError(…)
with the same arguments.extends
clause of a class definition. Subclass constructors that intend to inherit the specified AggregateError behaviour must include a super
call to the AggregateError When the
"%AggregateError.prototype%"
, « [[ErrorData]] »)."errors"
, The AggregateError
The initial value of AggregateError.prototype
is the intrinsic object
This property has the attributes { [[Writable]]:
The AggregateError prototype object:
The initial value of AggregateError.prototype.constructor
is the intrinsic object
This property has the attributes { [[Writable]]:
The initial value of AggregateError.prototype.message
is the empty String.
This property has the attributes { [[Writable]]:
The initial value of AggregateError.prototype.name
is "AggregateError"
.
This property has the attributes { [[Writable]]:
AggregateError instances are ordinary objects that inherit properties from their AggregateError prototype object and have an [[ErrorData]] internal slot whose value is Object.prototype.toString
(
The any
function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError
holding the rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.
The any
function requires its Promise
When the PerformPromiseAny abstract operation is called with arguments iteratorRecord, constructor, resultCapability, and promiseResolve, the following steps are taken:
AggregateError
object."errors"
, Promise.any
Reject Element Functions"then"
, « resultCapability.[[Resolve]], rejectElement »).Promise.any
Reject Element FunctionsA Promise.any
reject element function is an anonymous built-in function that is used to reject a specific Promise.any
element. Each Promise.any
reject element function has [[Index]], [[Errors]], [[Capability]], [[RemainingElements]], and [[AlreadyCalled]] internal slots.
When a Promise.any
reject element function is called with argument x, the following steps are taken:
AggregateError
object."errors"
, The "length"
property of a Promise.any
reject element function is 1.
The abstract operation IterableToList performs the following steps: