ReactionHandler
@rotorsoft/act-root / act/src / ReactionHandler
Type Alias: ReactionHandler<TEvents, TKey, TActions, TActor>
ReactionHandler<
TEvents,TKey,TActions,TActor> = (event,stream,app) =>Promise<Snapshot<Schema,TEvents> |void>
Defined in: libs/act/src/types/reaction.ts:52
Reaction handler function that processes committed events.
Reaction handlers respond to events asynchronously. They can:
- Perform side effects (send emails, call APIs, log, etc.)
- Return an action tuple to trigger another action
- Return
voidorundefinedfor side-effect-only reactions
Handlers are called during drain cycles and support automatic retries with configurable error handling.
Type Parametersโ
TEventsโ
TEvents extends Schemas
Event schemas
TKeyโ
TKey extends keyof TEvents
Event name
TActionsโ
TActions extends Schemas = Schemas
Action schemas (defaults to Schemas for stored reactions)
TActorโ
Actor type extending base Actor
Parametersโ
eventโ
Committed<TEvents, TKey>
The committed event that triggered this reaction
streamโ
string
The target stream name for this reaction
appโ
IAct<TEvents, TActions, TActor>
Returnsโ
Promise<Snapshot<Schema, TEvents> | void>
Promise resolving to an action tuple or void
Examplesโ
const sendEmail: ReactionHandler<Events, "UserCreated"> = async (event) => {
await emailService.send(event.data.email, "Welcome!");
};
const reduceInventory: ReactionHandler<Events, "OrderPlaced"> = async (event) => {
return ["reduceStock", { amount: event.data.items.length }];
};
Seeโ
Reaction for complete reaction configuration