Skip to main content

ReactionHandler

@rotorsoft/act-root


@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 void or undefined for 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

TActor extends Actor = Actor

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