This is a helper function to set a timeout on a promise. It is designed to be used with the magrittr pipe %>%.

timeout(
  x = NULL,
  delay = 0,
  msg = paste("The delay of", delay, "seconds expired.\n")
)

Arguments

x

An object.

delay

Number of seconds before rejecting the promise.

msg

Message if the timeout expires.

Value

A promise which fulfills when x fulfills before the delay expires: in this case, the value of the returned promise is the value of x. If x is not a fulfilled promise when the delay expires, the returned promise is rejected.

Examples

if (FALSE) { library(promises) value <- runif(1) pr <- promise(function(resolve, reject) ~ later::later(~ resolve(value), 0.1)) pr %>% timeout(10) %...>% { cat("value: ", ., "\n") } %...!% { cat("error:", .$message, "\n") } }