hold: Hold while an asynchronous task runs

Description Usage Arguments Details Value Examples

View source: R/hold.R

Description

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

Usage

1
2
3
4
5
6
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.

Details

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

Value

The value of the promise once resolved.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 

library(promises)
library(later)

pr <- promise(~ later(~ resolve("result of the async task"), 1))
value <- hold(pr)
cat(value, "\n")

## End(Not run)

RLesur/crrri documentation built on March 20, 2021, 8:47 a.m.