| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/utils.R |
| 3 |
\name{promise_all} |
| 4 |
\alias{promise_all} |
| 5 |
\alias{promise_race} |
| 6 |
\title{Combine multiple promise objects} |
| 7 |
\usage{ |
| 8 |
promise_all(..., .list = NULL) |
| 9 |
|
| 10 |
promise_race(..., .list = NULL) |
| 11 |
} |
| 12 |
\arguments{ |
| 13 |
\item{...}{Promise objects. Either all arguments must be named, or all |
| 14 |
arguments must be unnamed. If \code{.list} is provided, then these arguments are |
| 15 |
ignored.} |
| 16 |
|
| 17 |
\item{.list}{A list of promise objects--an alternative to \code{...}.} |
| 18 |
} |
| 19 |
\value{ |
| 20 |
A promise. |
| 21 |
|
| 22 |
For \code{promise_all}, if all of the promises were successful, the returned |
| 23 |
promise will resolve to a list of the promises' values; if any promise |
| 24 |
fails, the first error to be encountered will be used to reject the |
| 25 |
returned promise. |
| 26 |
|
| 27 |
For \code{promise_race}, the first of the promises to either fulfill or reject |
| 28 |
will be passed through to the returned promise. |
| 29 |
} |
| 30 |
\description{ |
| 31 |
Use \code{promise_all} to wait for multiple promise objects to all be successfully |
| 32 |
fulfilled. Use \code{promise_race} to wait for the first of multiple promise |
| 33 |
objects to be either fulfilled or rejected. |
| 34 |
} |
| 35 |
\examples{ |
| 36 |
p1 <- promise(\(resolve, reject) later::later(\() resolve(1), delay = 1)) |
| 37 |
p2 <- promise(\(resolve, reject) later::later(\() resolve(2), delay = 2)) |
| 38 |
|
| 39 |
# Resolves after 1 second, to the value: 1 |
| 40 |
promise_race(p1, p2) |> |
| 41 |
then(\(x) { |
| 42 |
cat("promise_race:\n") |
| 43 |
str(x) |
| 44 |
}) |
| 45 |
|
| 46 |
# Resolves after 2 seconds, to the value: list(1, 2) |
| 47 |
promise_all(p1, p2) |> |
| 48 |
then(\(x) { |
| 49 |
cat("promise_all:\n") |
| 50 |
str(x) |
| 51 |
}) |
| 52 |
|
| 53 |
} |