A reference class for managing multi-threaded operations in R using the callr package.
Arguments
- globalArgs
A
listof global arguments to be used in the worker function.- fun
A function or character string specifying the work to be done.
- ...
Additional arguments for the worker function.
- args
A
listof arguments needed inside the functionfun.- libraryNames
A
charactervector of library names to load in the worker process.- srcFiles
A
charactervector of source file paths to load in the worker process.- globalArgsRequired
A
logicalvalue indicating whether global arguments are required.
Value
A character string representation of the function.
A logical value indicating whether the thread has been started.
A logical value indicating whether the thread has been cancelled.
A logical value indicating whether the thread is in progress.
The result of the background process or NULL if the thread was cancelled or failed.
Fields
backgroundDataLoaderAn object of type
ANYthat represents the background process.threadConsoleLogFileA
characterstring representing the path to the log file for the thread console.globalArgsA
listof global arguments passed to the worker function.startTimeA
POSIXctobject representing the start time of the thread.endTimeA
POSIXctobject representing the end time of the thread.cancelledA
logicalvalue indicating whether the thread has been cancelled.
See also
ExtendedTask
for an alternative approach to realize background processes in shiny.
Examples
if (FALSE) { # \dontrun{
multiThreading <- MultiThreading$new()
multiThreading$doWork(
fun = function() {
Sys.sleep(3)
return(sample(1:9))
},
srcFiles = list.files("R", pattern = "\\.R$"),
globalArgsRequired = FALSE
)
multiThreading$isWorkInProgress()
multiThreading$printThreadLog()
multiThreading$getResult()
} # }
