Skip to contents

A reference class for managing multi-threaded operations in R using the callr package.

Arguments

globalArgs

A list of 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 list of arguments needed inside the function fun.

libraryNames

A character vector of library names to load in the worker process.

srcFiles

A character vector of source file paths to load in the worker process.

globalArgsRequired

A logical value 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

backgroundDataLoader

An object of type ANY that represents the background process.

threadConsoleLogFile

A character string representing the path to the log file for the thread console.

globalArgs

A list of global arguments passed to the worker function.

startTime

A POSIXct object representing the start time of the thread.

endTime

A POSIXct object representing the end time of the thread.

cancelled

A logical value 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()
} # }