timeout: Set a timeout

Description Usage Arguments Value Examples

View source: R/wait.R

Description

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

Usage

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
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") }

## End(Not run)

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