stream

fun stream(model: AggregateModel<*>, command: Command<*>): Flow<CommandResult>

Executes command on model's aggregate and emits a result for each hop of its wait plan as it is reached, one per command: a hop after a saga's emits one result for each command the saga derived, as each one reaches it, in the order they arrive, and is complete with the last of them. The command is executed when the flow is collected.

  • The flow completes after the final result, the last one emitted: the last hop's last command, a saga hop that derived nothing before the plan's last hop (marked CommandResult.chainEnded, with the hops not reached as CommandResult.pending), the first failure or rejection of any command on the chain (emitted at once, with nothing after it), a duplicate stopped at its last known hop, or a timeout (ResultCodes.WAIT_TIMEOUT, at the last hop completed). A plan rejected at admission emits only that rejection, at ACCEPTED.

  • A plan whose only hop is ACCEPTED still runs the command before the flow completes; accept answers it at once instead.

  • The timeout bounds the execution too: a command whose outcome is not known by the deadline ends the wait at ACCEPTED, timed out, and goes on executing in this coordinator's scope, as does one whose collector cancels the flow first; its outcome is logged. The deadline does not depend on the collector's context, and the flow runs in this coordinator's execution context, handing its results to the collector.

  • Outcomes are results, never errors: the flow fails only when the execution itself throws while it is waited for, and is cancelled with its collector. Either way the wait is unregistered, and later signals for it are dropped.