async (version 0.0.0.9004)

when_some: Resolve a deferred as soon as some deferred from a list resolve

Description

when_some creates a deferred value that is resolved as soon as the specified number of deferred values resolve.

Usage

when_some(count, ..., .list = list())

when_any(..., .list = list())

Arguments

count

Number of deferred values that need to resolve.

...

Deferred values.

.list

More deferred values.

Value

A deferred value, that is conditioned on all deferred values in ... and .list.

Details

when_any is a special case for a single.

If the specified number of deferred values cannot be resolved, then when_any throws an error.

async has auto-cancellation, so if the required number of deferred values are resolved, or too many of them throw error, the rest of the are cancelled.

If when_any throws an error, then all the underlying error objects are returned in the errors member of the error object thrown by when_any.

See Also

when_all()

Examples

Run this code
# NOT RUN {
## Use the URL that returns first
afun <- function() {
  u1 <- http_get("https://eu.httpbin.org")
  u2 <- http_get("https://eu.httpbin.org/get")
  when_any(u1, u2)$then(function(x) x$url)
}
synchronise(afun())
# }

Run the code above in your browser using DataLab