if (FALSE) {
# requires a sub-process to run the code
# Basic usage
a <- 1
async_works(1:10, function(ii){
ii + a # sub-process don't know a, hence must pass a as globals
}, .globals = list(a = a))
# non-blocking case
system.time({
check <- async_works(1:10, function(ii){
# simulating process, run run run
Sys.sleep(ii)
Sys.getpid()
}, .wait = FALSE)
})
# check the results
res <- check(timeout = 0.1)
attr(res, 'resolved') # whether it's resolved
# block the session waiting for the results
res <- check(timeout = Inf)
attr(res, 'resolved')
}
Run the code above in your browser using DataLab