runParallel: Run a list of functions parallel

Description Usage Arguments Details Value See Also Examples

Description

runParallel runs its input tasks parallel until all complete and returns either a named list (on error NULL) or the value of a given callback.

Usage

1
runParallel(tasks = list(NULL), cb = NULL)

Arguments

tasks

List of functions (anonymous and named) required.

cb

Anonymous or named function with signature cb(error, data) optional.

Details

If an error is encountered while calling the tasks without a callback runParallel immediately stops execution and returns NULL. If an error is encountered and a callback is defined runParallel immediately stops execution and calls the callback with the data parameter set to NULL and the error parameter set to the encountered error. Thus, the callback will always have only one non-NULL argument. Within the callback simply check for an error with is.null(error). If the error object is not NULL it has a property $task indicating the function that failed.

Value

If cb is NULL the tasks' return values are returned in a named list (on error NULL). If cb is a function it is called upon completion of all tasks and gets passed an error value (default NULL) as first parameter and a named list of the tasks' return values (on error NULL) as second parameter.

See Also

runSeries runWaterfall runRace https://github.com/feross/run-parallel

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
callback <- function(err, d) {
  if (is.null(err)) d else stop(err, err$task)
}
runParallel(list(function(i=0L) while (i < 1e6L) i <- i + 1L,
                 function() {Sys.sleep(5L); return(419L)}),
            callback)

## End(Not run)

chiefbiiko/runr documentation built on May 28, 2019, 7:17 p.m.