Skip to content
Snippets Groups Projects
Unverified Commit cb30cb98 authored by Todor Kondic's avatar Todor Kondic
Browse files

api: Update concurrency

* R/api.R(concurrency): Updated. Add comments and allow the plan to be
  set from outside shinyscreen (in accordance with the policy of the
  future package that users should have the control). Also, make
  debugging slightly easier by substituting future::future call with
  identity when debugging.
parent ee35658d
No related branches found
No related tags found
No related merge requests found
......@@ -172,10 +172,33 @@ verify_data <- function(conf,all_sets) {
## @export
concurrency <- function(m) {
m$conf$workers <- if (!is.null(m$conf$workers)) m$conf$workers else NO_WORKERS
future::plan("multiprocess",workers=m$conf$workers)
message("workers: ",m$conf$workers)
## Reads the concurrency entry in the config. It is optional, if
## not given, then it is up to the user to define the plan of the
## futures package. If present, it contains at least the `plan'
## specification. It can also contain `workers` entry specifying
## the number of workers. If that entry is absent, the default
## number of workers is NO_WORKERS from the resources.R.
workers <- m$conf$concurrency$workers
plan <- m$conf$concurrency$plan
if (!is.null(plan)) {
n <- if (!is.null(workers)) workers else NO_WORKERS
if (!is.na(n)) future::plan(plan,workers=workers) else future::plan(plan)
m$conf$concurrency$workers <- n
} else {
m$conf$concurrency$workers <- NA
m$conf$concurrency$plan <- "user"
}
message("plan: ",m$conf$concurrency$plan)
message("workers: ",m$conf$concurrency$workers)
## So we can actually debug.
m$future <- if (!m$conf$debug)
future::future
else {
message("Debug: futures evaluate as identity")
function(x,...) identity(x)
}
m
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment