maac_workflow library

Classes

ActionWorkflowStep<TContext>
A WorkflowStep defined by passing its handler functions directly, instead of subclassing WorkflowStep. Reach for this for simple steps — a few lines calling an API or writing a field onto the context — where a whole new class would be needless boilerplate. Fully interoperable with every decorator/composite in this package, since it implements the exact same WorkflowStep interface a subclass would.
CancellationToken
ConcurrencyStrategy
How ManagedWorkflowRunner.run behaves when called again while a previous run is still in flight.
ConditionalStep<TContext>
FlowContext
A key-value store shared across every step of a workflow, enforcing "scoped immutability": once a key has been written by a step, only that same step may write it again (e.g. from its own rollback) — every other step gets read-only access to it.
InteractiveStep<TContext, TInput>
A WorkflowStep that pauses and waits for an external signal — typically a UI form submission — instead of resolving on its own.
ManagedWorkflowRunner<TContext extends FlowContext>
Wraps a WorkflowRunnerFactory with one of three ConcurrencyStrategy behaviors for what happens when run is called again while a previous call hasn't finished yet: ConcurrencyStrategy.ignore, ConcurrencyStrategy.cancelExisting, or ConcurrencyStrategy.enqueue.
ParallelRunHandle<TContext extends FlowContext>
A single invocation started by ParallelWorkflowRunner.run — its own isolated runner/context, not shared with any other concurrent run.
ParallelStepGroup<TContext extends FlowContext>
Runs subSteps concurrently as a single WorkflowStep — the concurrent counterpart to WorkflowStepGroup's sequential composition. Succeeds only if every sub-step succeeds or is skipped; fails with the first failure encountered (the others are still awaited to completion, per Future.wait's default behavior, before this step resolves).
ParallelWorkflowRunner<TContext extends FlowContext>
The "parallel" concurrency strategy: every call to run spins up a fully independent WorkflowRunner (via createRunner) with its own isolated FlowContext, running concurrently with any other in-flight calls rather than cancelling or queuing them. See ManagedWorkflowRunner for the "one current run" strategies (ignore/cancelExisting/enqueue) and SharedWorkflowRunner for joinOrCreate.
RetryStepDecorator<TContext>
SessionJoinHandle<TContext extends FlowContext>
A single caller's attachment to a SharedWorkflowRunner session, returned by SharedWorkflowRunner.join.
SharedWorkflowRunner<TContext extends FlowContext>
Implements the joinOrCreate concurrency strategy: if no session is active, join starts a new one via createRunner; if one is already in flight, join merges into it instead of starting a second physical run — avoiding duplicate work and UI flicker for shared resources like a global loading indicator.
StepFailure
StepResult
Represents the result of an individual step execution.
StepSkipped
StepSuccess
SustainedWorkflowStep<TContext>
A WorkflowStep for work with no natural completion of its own — a live stream subscription, an open connection, a polling loop, anything that's simply "started" and then just keeps running. Unlike an ordinary step, execute() deliberately never resolves on its own once start returns — it stays pending until this step is cancelled or deactivated (e.g. by a superseding ManagedWorkflowRunner.cancelExisting run), at which point stop tears the work down.
TimeoutStepDecorator<TContext>
Wraps step so that it fails with a StepFailure holding a TimeoutException if it doesn't complete within timeout.
WorkflowCancelled<TContext>
WorkflowFailure<TContext>
WorkflowListener<TContext>
Listener interface for workflow lifecycle events, useful for global loading spinners, analytics, and metrics.
WorkflowProgress
A live, queryable snapshot of a WorkflowRunner's progress: which step is currently executing (forward or rollback), and the last known StepStatus of every step reached so far.
WorkflowResult<TContext>
Represents the overall outcome of a workflow execution.
WorkflowRunner<TContext extends FlowContext>
WorkflowStep<TContext>
WorkflowStepEvent
WorkflowStepGroup<TContext extends FlowContext>
Lets a whole sub-pipeline of steps be embedded as a single WorkflowStep inside a parent WorkflowRunner, so large flows can be composed out of named, independently testable sub-flows instead of one flat list of steps.
WorkflowSuccess<TContext>

Enums

JoinCompletionRule
Governs when a SharedWorkflowRunner session's SharedWorkflowRunner.isSessionActive signal closes, once multiple callers have SharedWorkflowRunner.joined one shared run.
StepStatus
The execution status of a workflow step, useful for audit logging, analytics, and driving a live step indicator UI via WorkflowRunner.progress.

Typedefs

StepAction<TContext> = FutureOr<StepResult> Function(TContext context, CancellationToken token)
StepCanRunFn<TContext> = FutureOr<bool> Function(TContext context)
StepDeactivateFn<TContext> = FutureOr<void> Function(TContext context)
StepRollbackFn<TContext> = FutureOr<void> Function(TContext context)
SustainedStepStart<TContext> = FutureOr<void> Function(TContext context, void fail(Object error, [StackTrace? stackTrace]))
SustainedStepStop<TContext> = FutureOr<void> Function(TContext context)
WorkflowRunnerFactory<TContext extends FlowContext> = WorkflowRunner<TContext> Function()
Builds a fresh WorkflowRunner (with fresh step instances) for one logical run. Concurrency-control wrappers (ManagedWorkflowRunner, ParallelWorkflowRunner, SharedWorkflowRunner) call this once per logical run rather than reusing a single instance, because both WorkflowRunner and stateful steps (e.g. InteractiveStep) hold per-instance mutable state that two overlapping runs can never safely share.

Exceptions / Errors

QueueFullException
The WorkflowFailure.error a call resolves with when ConcurrencyStrategy.enqueue's maxQueueLength is already full — the call is rejected, not queued, but (like every other outcome in this package) reported by resolving normally rather than throwing to the caller.
StepExecutionException
WorkflowCancelledException