@hyperfrontend/state-machine/coordinated-async-operationcoordinated-async-operation
Orchestrator for multiple related async processes, exposing aggregate state across the group.
CoordinatedAsyncProcess wraps a set of AsyncOperation instances and presents them as one unit: lifecycle actions (start, pause, cancel) fan out to every member; selectors (inProgress, done, failed, ...) report the group-level state derived from the constituents. Use this when an application step depends on several async pieces completing together (fetching a record and its related entities, say) and you want a single object to render against rather than coordinating the individual processes by hand.
API Reference§
◇ Classes
Coordinates multiple async operations, allowing them to be started, cancelled, or paused together.
Constructor
§
new CoordinatedAsyncProcess( )Methods
§
readonly cancelAll( ): voidCancels every registered operation, in registration order.
Each cancellation only changes that operation's state; the processes themselves keep running to completion.
Each cancellation only changes that operation's state; the processes themselves keep running to completion.
§
readonly pauseAll( ): voidPauses every registered operation, in registration order.
Each pause only changes that operation's state; the processes themselves are not suspended.
Each pause only changes that operation's state; the processes themselves are not suspended.
§
readonly registerProcess( process: AsyncProcess): CoordinatedAsyncProcessAdds a process to the group, wrapped in an
Registration does not run the process;
AsyncOperation of its own. Registration does not run the process;
startAll does. Processes keep the order they were registered in.Parameters
| Name | Type | Description |
|---|---|---|
§process | AsyncProcess | The asynchronous work to add |
Returns
CoordinatedAsyncProcessThis coordinator, so registrations can be chained
Starts every registered process at once.
Each process runs through its own operation, which catches its rejection and records it as that operation's failure, so one process failing neither stops the others nor rejects the returned promise.
Each process runs through its own operation, which catches its rejection and records it as that operation's failure, so one process failing neither stops the others nor rejects the returned promise.
Returns
Promise< void[ ]>Resolves once every process has settled, with one entry per operation and no values
Example
Coordinating multiple async operations
const coordinator = new CoordinatedAsyncProcess()
.registerProcess(fetchUsers)
.registerProcess(fetchOrders)
await coordinator.startAll()