async (version 0.0.0.9004)

synchronise: Synchronously wrap asynchronous code

Description

Evaluate an expression in an async phase. It creates an event loop, then evaluates the supplied expression. If its result is a deferred value, it keeps running the event loop, until the deferred value is resolved, and returns its resolved value.

Usage

synchronise(expr)

Arguments

expr

Async function call expression. If it does not evaluate to a deferred value, then it is just returned.

Details

If an error is not handled in the async phase, synchronise() will re-throw that error.

synchronise() cancels all async processes on interrupt or external error.

Examples

Run this code
# NOT RUN {
http_status <- function(url, ...) {
  http_get(url, ...)$
    then(function(x) x$status_code)
}

synchronise(http_status("https://eu.httpbin.org/status/418"))
# }

Run the code above in your browser using DataCamp Workspace