use std/flow::emit
use std/ops/option/block::unwrap
use root/command::Command
use root/environment::Environment
use root/exec::Executor
use root/local::|local_executor
use root/exec::execOnce as generalExecOnce
use root/exec::spawnOnce as generalSpawnOnce
/**
Execute a single command on the local machine, triggered by a launch signal.
Convenience wrapper around `execOnce` that automatically obtains the local executor.
`command` is run with the optional `environment` when `launch` fires.
`started`, `completed`, `failed`, `error`, `exit`, and `finished` behave identically to `execOnce`.
*/
treatment execOnce(command: Command, environment: Option<Environment> = _)
input launch: Block<void>
output started: Block<void>
output finished: Block<void>
output completed: Block<void>
output failed: Block<void>
output error: Block<string>
output exit: Block<Option<i32>>
{
emitExecutor: emit<Option<Executor>>(value = |local_executor())
unwrapExecutor: unwrap<Executor>()
generalExecOnce(command = command, environment = environment)
Self.launch -> emitExecutor.trigger,emit -> unwrapExecutor.option,value -> generalExecOnce.executor
Self.launch -------------------------------------------------------------> generalExecOnce.launch
generalExecOnce.started ----> Self.started
generalExecOnce.finished ---> Self.finished
generalExecOnce.completed --> Self.completed
generalExecOnce.failed -----> Self.failed
generalExecOnce.error ------> Self.error
generalExecOnce.exit -------> Self.exit
}
/**
Spawn a single command on the local machine with stdio streams, triggered by a launch signal.
Convenience wrapper around `spawnOnce` that automatically obtains the local executor.
`command` is spawned with the optional `environment` when `launch` fires.
Connects `stdin`, `stdout`, and `stderr` streams to the process.
`started`, `completed`, `failed`, `error`, `exit`, and `finished` behave identically to `spawnOnce`.
*/
treatment spawnOnce(command: Command, environment: Option<Environment> = _)
input launch: Block<void>
input stdin: Stream<byte>
output stdout: Stream<byte>
output stderr: Stream<byte>
output started: Block<void>
output finished: Block<void>
output completed: Block<void>
output failed: Block<void>
output error: Block<string>
output exit: Block<Option<i32>>
{
emitExecutor: emit<Option<Executor>>(value = |local_executor())
unwrapExecutor: unwrap<Executor>()
generalSpawnOnce(command = command, environment = environment)
Self.launch -> emitExecutor.trigger,emit -> unwrapExecutor.option,value -> generalSpawnOnce.executor
Self.launch -------------------------------------------------------------> generalSpawnOnce.launch
Self.stdin --------> generalSpawnOnce.stdin
generalSpawnOnce.stdout --> Self.stdout
generalSpawnOnce.stderr --> Self.stderr
generalSpawnOnce.started ----> Self.started
generalSpawnOnce.finished ---> Self.finished
generalSpawnOnce.completed --> Self.completed
generalSpawnOnce.failed -----> Self.failed
generalSpawnOnce.error ------> Self.error
generalSpawnOnce.exit -------> Self.exit
}