Skip to content

all

Await many promises

559 bytes

The all function is similar to the builtin Promise.all or Promise.allSettled functions. Given a list (or object) of promises, if any errors are thrown, all errors are gathered and thrown in an AggregateError.

Using an Array

Passing an array as an argument will return the resolved promise values as an array in the same order.

import * as
import _
_
from 'radashi'
const [
const user: any
user
] = await
import _
_
.
all<[any, any, any]>(input: [any, any, any]): Promise<any> (+2 overloads)
export all

Wait for all promises to resolve. Errors from rejected promises are collected into an AggregateError.

@seehttps://radashi.js.org/reference/async/all

@example

const [user] = await all([
api.users.create(...),
s3.buckets.create(...),
slack.customerSuccessChannel.sendMessage(...)
])

@version12.1.0

all
([
any
api
.
any
users
.
any
create
(...),
any
s3
.
any
buckets
.
any
create
(...),
any
slack
.
any
customerSuccessChannel
.
any
sendMessage
(...)
])

Using an Object

Passing an object as an argument will return an object with the same keys and the values as the resolved promise values.

import * as
import _
_
from 'radashi'
const {
const user: any
user
} = await
import _
_
.
all<{
user: any;
bucket: any;
message: any;
}>(input: {
user: any;
bucket: any;
message: any;
}): Promise<{
user: any;
bucket: any;
message: any;
}> (+2 overloads)
export all

Check each property in the given object for a promise value. Wait for all promises to resolve. Errors from rejected promises are collected into an AggregateError.

The returned promise will resolve with an object whose keys are identical to the keys of the input object. The values are the resolved values of the promises.

@seehttps://radashi.js.org/reference/async/all

@example

const { user } = await all({
user: api.users.create(...),
bucket: s3.buckets.create(...),
message: slack.customerSuccessChannel.sendMessage(...)
})

all
({
user: any
user
:
any
api
.
any
users
.
any
create
(...),
bucket: any
bucket
:
any
s3
.
any
buckets
.
any
create
(...),
message: any
message
:
any
slack
.
any
customerSuccessChannel
.
any
sendMessage
(...)
})