wait: Return a promise after a delay

Description Usage Arguments Details Value Examples

View source: R/wait.R

Description

This is a helper function that returns a promise after a delay. It can be used with any pipe and any object (see examples).

Usage

1
wait(x, delay = 0)

Arguments

x

An object.

delay

Number of seconds before resolving the promise.

Details

The value of the returned promise depends on the class of x. If x can be coerced to a promise (using promises::as.promise()), the value of the returned promise is identical to the value of promises::as.promise(x) once fulfilled; otherwise the value of the returned promise is x after the delay.

Value

A promise. See details for the value of the fulfilled promise.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
library(promises)

value <- runif(1)
pr <- promise_resolve(value)

# works with `magrittr` pipe
pr %>%
  wait(1) %>%
  then(~ cat(., "\n"))

# works with `promises` pipe
pr %...>%
  wait(1) %...>%
{ cat(., "\n") }

# also works with any object
value %>%
  wait(1) %>%
  then(~cat(., "\n"))

## End(Not run)

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