external_process: External process via a process generator

View source: R/xprocess.R

external_processR Documentation

External process via a process generator

Description

Wrap any processx::process object into a deferred value. The process is created by a generator function.

Usage

external_process(process_generator, error_on_status = TRUE, ...)

Arguments

process_generator

Function that returns a processx::process object. See details below about the current requirements for the returned process.

error_on_status

Whether to fail if the process terminates with a non-zero exit status.

...

Extra arguments, passed to process_generator.

Value

Deferred object.

Current requirements for process_generator:

  • It must take a ... argument, and pass it to processx::process$new().

  • It must use the poll_connection = TRUE argument. These requirements might be relaxed in the future.

If you want to obtain the standard output and/or error of the process, then process_generator must redirect them to files. If you want to discard them, process_generator can set them to NULL.

process_generator should not use pipes ("|") for the standard output or error, because the process will stop running if the pipe buffer gets full. We currently never read out the pipe buffer.

Examples

## Not run: 
lsgen <- function(dir = ".", ...) {
  processx::process$new(
    "ls",
    dir,
    poll_connection = TRUE,
    stdout = tempfile(),
    stderr = tempfile(),
    ...
  )
}
afun <- function() {
  external_process(lsgen)
}
synchronise(afun())

## End(Not run)

gaborcsardi/async documentation built on Nov. 20, 2024, 4:51 p.m.