Skip to content

Actor

Defined in: src/Actor.ts:17

Base class for user actors. Subclasses must override onReceive. Lifecycle hooks (preStart, postStop, preRestart, postRestart) have sensible defaults but can be overridden.

Actors are single-threaded by construction: the runtime guarantees that onReceive is never invoked concurrently for the same actor. If onReceive returns a Promise, the runtime awaits it before starting the next message.

TMsg = unknown

new Actor<TMsg>(): Actor<TMsg>

Actor<TMsg>

abstract onReceive(message): void | Promise<void>

Defined in: src/Actor.ts:38

Main message handler. Receives each envelope dequeued from the mailbox. A thrown error (sync or async) is caught by the supervisor.

TMsg

void | Promise<void>


postRestart(_reason): void | Promise<void>

Defined in: src/Actor.ts:55

Called on the fresh instance after a restart. Default: call preStart().

Error

void | Promise<void>


postStop(): void | Promise<void>

Defined in: src/Actor.ts:44

Called after the actor has been terminated. Children are already stopped.

void | Promise<void>


preRestart(_reason, _message?): void | Promise<void>

Defined in: src/Actor.ts:50

Called before a restart, on the instance about to be thrown away. The default stops children and then calls postStop().

Error

TMsg

void | Promise<void>


preStart(): void | Promise<void>

Defined in: src/Actor.ts:41

Called after construction and before the first message is processed.

void | Promise<void>


supervisorStrategy(): SupervisorStrategy

Defined in: src/Actor.ts:63

Supervisor strategy for this actor’s children. Defaults to restart, up to 10 times per minute, then stop.

SupervisorStrategy