synchronise: Synchronously wrap asynchronous code

View source: R/synchronise.R

synchroniseR Documentation

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


http_status <- function(url, ...) {
  http_get(url, ...)$
    then(function(x) x$status_code)
}

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


r-lib/async documentation built on March 24, 2024, 6:20 p.m.