"delay" returns a promise which resolves only after the specified number of seconds. This uses the R event loop via later. In an [async] construct you can use await(delay(secs)) to yield control, for example if you need to poll in a loop.

delay(secs, expr = NULL)

Arguments

secs

The promise will resolve after at least this many seconds.

expr

The value to resolve with; will be forced after the delay.

Value

An object with class "promise".

Examples

# print a message after a few seconds
async({await(delay(10)); cat("Time's up!\n")})
#> async({
#>     await(delay(10))
#>     cat("Time's up!\n")
#> })
#> <environment: 0x55b5d0be04e0>
#> <async [pending at `.{1.await__then`]>
#> <Promise [pending]>