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
Dispatcher<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