Repository F# setup
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Console
open Axial.FileSystem
open Axial.ProcessProcess identity and graceful stop
Process.onStarted runs once for each stage immediately after the operating-system process starts and before Axial publishes any output from that stage. The ProcessStarted value contains the zero-based stage index, rendered command, start time, process ID, and Close and Signal flows.
Keep the handle in application state when a supervisor needs to restart or stop a long-lived child. Sending a request after the stage exits succeeds without doing anything.
let supervise publish (command: ProcessCommand) =
command
|> Process.onStarted (fun started ->
publish started
Flow.succeed ())
|> Process.toFlow
supervise: (ProcessStarted -> unit) -> ProcessCommand -> Flow<'a,ProcessError,ProcessResult>publish: ProcessStarted -> unitcommand: ProcessCommandAxial.Process.ProcessCommandOne immutable command; configure it before connecting stages.
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Process.ProcessonStarted: (ProcessStarted -> Flow<unit,Never,unit>) -> ^a -> ProcessSpecInvokes the handler once for every stage, immediately after it starts and before output is observed.
started: ProcessStartedAxial.Flowsucceed: 'value -> Flow<'env,'error,'value>Same as ok. The value to wrap in a successful flow. A flow that always succeeds with the provided value. let result = Flow.succeed 42 |> Flow.run () // result = Success 42
toFlow: ^a -> Flow<'b,ProcessError,ProcessResult>Requires & types
Requires: open Axial; open Axial.Process (packages: Axial, Axial.Process)val supervise: (ProcessStarted -> unit) -> ProcessCommand -> Flow<'a,ProcessError,ProcessResult>A completed StageResult also contains ProcessId, so batch and streaming executions retain the identity of every stage.
Coming from System.Diagnostics.Process
ProcessStarted.Close differs from .NET's Process.CloseMainWindow / Process.Kill and from sending one signal: it owns whole-execution shutdown and escalates after configured grace periods, ultimately killing the process tree. Without a stop policy, it escalates immediately. Use ProcessStarted.Signal for a single request with no escalation.
Stop requests
ProcessStarted.Signal sends exactly one stage-local StopRequest, without taking ownership of shutdown. ProcessStarted.Close sends an initial request and, if it succeeds, starts coordinated shutdown of the entire execution. Both use the same mapping:
InterruptsendsSIGINTon Unix.TerminatesendsSIGTERMon Unix.HangupsendsSIGHUPon Unix.Signal numbersends that numeric Unix signal.CloseStdIncloses stdin when Axial owns the redirected pipe.CloseMainWindowasks a Windows GUI process to close its main window.
A request the platform or stage cannot support fails with ProcessError.StopUnsupported, and a request that was attempted but failed fails with ProcessError.StopFailed. .NET's ProcessStartInfo cannot create the new Windows process group required to target GenerateConsoleCtrlEvent safely. Axial therefore never sends a console event to group 0: Interrupt, Terminate, Hangup, and raw numeric signals return StopUnsupported on Windows; on Unix, CloseMainWindow returns StopUnsupported. A graceful-stop ladder skips unsupported steps, so it continues to its next step. CloseMainWindow is the Windows graceful-stop path.
The returned flow acknowledges the initial request; it does not wait for shutdown or native reap. Await the process execution for that. After shutdown starts, later Close requests succeed without sending another request or waiting for the active ladder, including when timeout started shutdown. Unsupported or failed initial requests do not start shutdown. A handle used after its stage exits is a no-op, even if other stages remain live.
Signal returns after delivery, not process exit. It neither starts nor restarts nor cancels an active ladder; while a ladder is running it still sends the requested action to the live stage. Its grace deadlines and first stop cause remain unchanged. A request after stage exit is a successful no-op. Unsupported and failed requests use the same typed errors as Close. Output observation continues after a standalone Signal, but an already-running ladder still stops observation.
Both pipeline and DSL users obtain these flows through onStarted; no separate signal DSL operator is needed.
let halfClose (started: ProcessStarted) =
started.Signal StopRequest.CloseStdIn
halfClose: ProcessStarted -> Flow<unit,ProcessError,unit>started: ProcessStartedAxial.Process.ProcessStartedA running stage that accepts one-shot requests or coordinated shutdown.
Signal: StopRequest -> Flow<unit,ProcessError,unit>Sends one stage-local request using the same platform mapping and typed errors as Close's initial request. Does not start, restart, cancel or otherwise own a shutdown ladder, even while one is running. Returns after delivery, not exit. CloseStdIn only half-closes owned stdin. After stage exit this is a no-op.
Axial.Process.StopRequestRequests a cooperative action from a running process stage.
CloseStdInCloses the stage's redirected standard-input pipe.
Requires & types
Requires: open Axial.Process (packages: Axial.Process)val halfClose: ProcessStarted -> Flow<unit,ProcessError,unit>Escalation on Close, interruption or timeout
By default, an accepted Close, interruption and process timeout immediately kill the complete process tree. Process.stopGracefully installs an ordered escalation ladder. Axial sends each request to every live stage, waits at most that step's duration for all stages to exit, and proceeds to the next request. It kills the process tree after the final grace period when stages remain alive.
let withGracefulStop (command: ProcessCommand) =
command
|> Process.stopGracefully [
StopRequest.CloseStdIn, TimeSpan.FromSeconds 1.
StopRequest.Terminate, TimeSpan.FromSeconds 5.
]
|> Process.toFlow
withGracefulStop: ProcessCommand -> Flow<'a,ProcessError,ProcessResult>command: ProcessCommandAxial.Process.ProcessCommandOne immutable command; configure it before connecting stages.
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Process.ProcessstopGracefully: (StopRequest * TimeSpan) list -> ^a -> ProcessSpecSends each request to all live stages on Close, interruption or timeout, waiting its grace period before escalating. A Close matching the first step reuses its initial delivery to that stage; the ladder runs once per execution. ProcessStarted.Signal sends only one request and never starts this policy.
Axial.Process.StopRequestRequests a cooperative action from a running process stage.
CloseStdInCloses the stage's redirected standard-input pipe.
System.TimeSpanRepresents a time interval.
FromSeconds: float -> TimeSpanReturns a that represents a specified number of seconds, where the specification is accurate to the nearest millisecond. A number of seconds, accurate to the nearest millisecond. An object that represents . is less than or greater than . -or- is . -or- is . is equal to .
TerminateSends SIGTERM on Unix or CTRL_BREAK_EVENT on Windows.
toFlow: ^a -> Flow<'b,ProcessError,ProcessResult>Requires & types
Requires: open Axial.Process; open System (packages: Axial.Process)val withGracefulStop: ProcessCommand -> Flow<'a,ProcessError,ProcessResult>For the common single-step policy, use [ StopRequest.Terminate, grace ]. When Close StopRequest.Terminate starts that policy, Axial reuses the initial signal for the addressed stage rather than sending it twice; other live stages receive the same first step. A different initial request precedes the configured ladder. All grace periods use the clock captured by the running execution, not the clock of the caller submitting Close.
Close is not a standalone signal or stdin half-close. Use Signal StopRequest.CloseStdIn to deliver EOF without a shutdown deadline, or Signal StopRequest.Terminate for one TERM without later escalation. To allow EOF to finish the child before owned escalation, configure [ StopRequest.CloseStdIn, grace ] and use Close. Application-protocol shutdown messages still go through the input source.
Cancellation remains Cause.Interrupt. A stage or overall timeout recorded first retains its typed error after graceful shutdown. When external Close is recorded first, the run reports its ordinary exit-code result (StageFailed for an unaccepted exit code), not a later timeout. Output observation stops when shutdown starts; do not use output callbacks to acknowledge subsequent signals.
Every execution starts the coordinator, including a single command without optional policies, so caller interruption and output-destination failure always have a live stop path. The ladder runs once per execution, including when Close races a timeout. If cancellation and a stage timeout both happen, the one observed first decides the result: a timeout recorded before cancellation keeps StageTimedOut, and otherwise the result is Cause.Interrupt. The later cause waits for the running ladder rather than killing early. Output-cap failures, broken pipeline destinations, and failed output callbacks also stop the remaining stages instead of waiting for their natural exit; the original output or destination failure remains the result.
CloseStdIn requests feeder cancellation and closes the pipe without waiting, so a blocking cancellation callback or a child that never reads its input cannot hold the ladder at that step.
A user InputSource.Stream is consumed by the stdin feeder fiber; only each stream write crosses the BCL task bridge. When a process exits or stdin is closed, Axial asks that fiber to stop and closes the pipe, which also releases a write blocked on a full pipe. The process execution then waits for the feeder, with no time limit, before it returns. A typed input failure or defect the feeder settles with is the execution's failure, including one raised while it stops; interruption and the pipe-closed errors caused by closing the pipe are not failures.
A source that ignores interruption keeps the execution waiting. To let the execution return without it, wrap that source in Flow.disconnect: the execution returns, the source keeps settling in its own fiber owned by the application, and its eventual defect is reported once to the fiber observer.
Axial.Process currently provides a live implementation only on .NET. The Fable build can type-check process specifications and test doubles, but it does not start Node child processes.

