delay: Delay async computation for the specified time

View source: R/delay.R

delayR Documentation

Delay async computation for the specified time

Description

Since R is single-threaded, the deferred value might be resolved (much) later than the specified time period.

Usage

delay(delay)

Arguments

delay

Time interval in seconds, the amount of time to delay to delay the execution. It can be a fraction of a second.

Value

A deferred object.

Examples


## Two HEAD requests with 1/2 sec delay between them
resp <- list()
afun <- async(function() {
  http_head("https://eu.httpbin.org?q=2")$
    then(function(value) resp[[1]] <<- value$status_code)$
    then(function(...) delay(1/2))$
    then(function(...) http_head("https://eu.httpbin.org?q=2"))$
    then(function(value) resp[[2]] <<- value$status_code)
})
synchronise(afun())
resp


gaborcsardi/async documentation built on Nov. 20, 2024, 4:51 p.m.