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

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

if (FALSE) { 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")) }