plumber supports async request handling in two ways. Either manual by
returning a promise from the handler, or automatic through the @async
tag /
async
argument in the handler functions. The
default evaluator is controlled by the plumber2.async
option or the
PLUMBER2_ASYNC
environment variable.
Usage
register_async(name, fun, dependency = NULL)
show_registered_async()
get_async(name = NULL, ...)
Arguments
- name
The name of the evaluator
- fun
A function that, upon calling it returns an evaluator taking an
expr
andenvir
argument. See the async evaluator functions for examples- dependency
Package dependencies for the evaluator.
- ...
Arguments passed on to the async function creator
Examples
if (FALSE) {
# Register an async evaluator based on future (the provided mirai backend is
# superior in every way so this is for illustrative purpose)
future_async <- function(...) {
function(expr, envir) {
promises::future_promise(
expr = expr,
envir = envir,
substitute = FALSE,
...
)
}
}
register_async("future", future_async, c("promises", "future"))
}