library(future)
plan(sequential)
# Use sequential plan
# 1. Change `plan` to 'multicore', 'multisession', or TRUE to enable
# multi-core, but still with progress information
# 2. Change plan=FALSE will use current future plan
res <- lapply_async2(100:200, function(x){
return(x+1)
}, callback = function(e){
sprintf('Input=%d', e)
}, plan = 'sequential')
# Disable callback message, then the function reduce to
# normal `future.apply::future_lapply`
res <- lapply_async2(100:200, function(x){
return(x+1)
}, callback = NULL, plan = FALSE)
if(interactive()) {
# PID are different, meaning executing in different sessions
lapply_async2(1:4, function(x){
Sys.getpid()
})
}
Run the code above in your browser using DataLab