ThinkR-open / mariobox

A Framework For Packaging {plumber} APIs
Other
38 stars 1 forks source link

feat: support for async function #2

Open ColinFay opened 2 years ago

ColinFay commented 2 years ago

Following a conversation with @psolymos:

Create a add_endpoint_async that will create the skeleton for a promise based endpoint handler.

Maybe add the information in the YAML so that when building the plumber.R file and running the API in run_dev

psolymos commented 2 years ago

Example skeleton:

library(promises)
library(future.callr)
plan(callr, workers = 2L)

#* @post /async_endpoint
function(req, res, callback) {
    if (missing(callback))
        callback <- NULL
    promises::future_promise({
        FUN(..., callback = callback)
    })
    list("Async job started")
}