when_some creates a deferred value that is resolved as soon as the
specified number of deferred values resolve.
A deferred value, that is conditioned on all deferred values
in ... and .list.
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.
httpbin <- webfakes::new_app_process(
webfakes::httpbin_app(),
opts = webfakes::server_opts(num_threads = 3)
)
## Use the URL that returns first
afun <- function() {
u1 <- http_get(httpbin$url("/get"))
u2 <- http_get(httpbin$url("/get"))
when_any(u1, u2)$then(function(x) x$url)
}
synchronise(afun())
#> [1] "http://127.0.0.1:40661/get"