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

View source: R/when_any.R

when_someR Documentation

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.

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.

Value

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

See Also

when_all()

Examples


## 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())


gaborcsardi/async documentation built on Nov. 20, 2024, 4:51 p.m.