Skip to main content
Version: Current

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:46

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​

IAct<TEvents, TActions, TActor>

Returns​

Promise<Snapshot<Schema, TEvents> | void>

Promise resolving to an action tuple or void

Example​

Side effect only

const sendEmail: ReactionHandler<Events, "UserCreated"> = async (event) => {
await emailService.send(event.data.email, "Welcome!");
};

See​

Reaction for complete reaction configuration