ZfaReactionBus class

A typed, decoupled reaction bus for use case choreography.

A bus chains use cases by registering typed reactions (onSuccess / onFailure). run executes an initial intent, and whenever a step's runtime (input, output) types match a registered reaction, the bus maps to the next intent, spawns a child ZfaContext via ZfaContext.childSpan (incrementing cascadeDepth by one and linking the causal span and cancellation token), and dispatches it. The chain stops when no reaction matches, and a circular chain is halted once it crosses maxCascadeDepth with a PolicyDeniedFailure carrying reason: 'cascadeDepth'.

Example

final bus = ZfaReactionBus();
bus.onSuccess<ImportOrderIntent, Order, CheckPriceIntent>(
  reactionId: 'order.import -> price.check',
  toIntent: (_, order) => CheckPriceIntent(order.productId),
);
final result = await bus.run(
  const ImportOrderIntent('order-1'),
  runner: dispatchUseCase,
  context: ZfaContext.root(),
);

Constructors

ZfaReactionBus({int maxCascadeDepth = 8})
Create a bus with the given loop guard (default 8).

Properties

hashCode → int
The hash code for this object.
no setterinherited
maxCascadeDepth → int
The maximum ZfaContext.cascadeDepth before a cascade is halted.
final
reactions → List<ZfaReaction>
The registered reactions, in registration order (the choreography graph).
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onFailure<I extends Object, N extends Object>({required String reactionId, required N toIntent(I intent, AppFailure failure)}) → ZfaReaction<I, AppFailure, N>
Register a reaction that fires when a use case of input I fails, mapping (intent, failure) to a recovery intent.
onSuccess<I extends Object, O extends Object, N extends Object>({required String reactionId, required N toIntent(I intent, O output)}) → ZfaReaction<I, O, N>
Register a reaction that fires when a use case of input I succeeds with output O, mapping (intent, output) to the next intent.
run(Object intent, {required ReactionRunner runner, required ZfaContext context}) → Future<Result<Object?, AppFailure>>
Execute intent and follow the reaction chain to its terminal result.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited