async (version 0.0.0.9004)

async_timeout: Asynchronous function call with a timeout

Description

If the deferred value is not resolved before the timeout expires, async_timeout() throws an async_timeout error.

Usage

async_timeout(task, timeout, ...)

Arguments

task

Asynchronous function.

timeout

Timeout as a difftime object, or number of seconds.

...

Additional arguments to task.

Value

A deferred value. An async_timeout error is thrown if it is not resolved within the specified timeout.

Examples

Run this code
# NOT RUN {
## You can catch the error, asynchronously
synchronise(
  async_timeout(function() delay(1/10)$then(function() "OK"), 1/1000)$
    catch(async_timeout = function(e) "Timed out",
          error = function(e) "Other error")
)

## Or synchronously
tryCatch(
  synchronise(
    async_timeout(function() delay(1/10)$then(function() "OK"), 1/1000)
  ),
  async_timeout = function(e) "Timed out. :(",
  error = function(e) paste("Other error:", e$message)
)
# }

Run the code above in your browser using DataCamp Workspace