Learn R Programming

crrri (version 0.0.13)

wait: Return a promise after a delay

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

wait(x, delay = 0)

Arguments

x

An object.

delay

Number of seconds before resolving the promise.

Value

A promise. See details for the value of the fulfilled 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.

Examples

Run this code
# 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"))
# }

Run the code above in your browser using DataLab