The hold() function is a helper to turn a promises::promise() in a synchronous value: the R session awaits the fulfillment of the promise and returns the value of the fulfilled promise. An error is thrown if the promise is rejected or a timeout expires. This is a wrapper around later::run_now().

hold(
  x,
  timeout = 30,
  msg = paste("The asynchronous job has not finished in the delay of", timeout,
    "seconds.")
)

Arguments

x

A promises::promise() object.

timeout

Number scalar, timeout in seconds. An error is thrown if the promise is still pending when the delay expires.

msg

Error message when the timeout expires.

Value

The value of the promise once resolved.

Details

This function must not be used inside a function that returns a promise. Otherwise, this will lead to an infinite loop.

Examples

if (FALSE) { library(promises) library(later) pr <- promise(~ later(~ resolve("result of the async task"), 1)) value <- hold(pr) cat(value, "\n") }