Skip to content

all

Await many promises

625 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 _ from 'radashi'
const [user] = await _.all([
api.users.create(...),
s3.buckets.create(...),
slack.customerSuccessChannel.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 _ from 'radashi'
const { user } = await _.all({
user: api.users.create(...),
bucket: s3.buckets.create(...),
message: slack.customerSuccessChannel.sendMessage(...)
})