Skip to content

DurableStateActor

Defined in: src/persistence/DurableStateActor.ts:32

Base class for actors that persist a single state value per persistenceId instead of an event log. State is loaded on startup (or an emptyState snapshot is used) and persisted after each mutation via persist(newState).

User code overrides onCommand with the command handler and calls this.state to read, this.persist(next) to write. Writes are optimistic — concurrent writers receive DurableStateConcurrencyError.

Cmd

S

new DurableStateActor<Cmd, S>(settings): DurableStateActor<Cmd, S>

Defined in: src/persistence/DurableStateActor.ts:36

DurableStateSettings<S>

DurableStateActor<Cmd, S>

Actor.constructor

readonly settings: DurableStateSettings<S>

Defined in: src/persistence/DurableStateActor.ts:36

abstract onCommand(cmd): void | Promise<void>

Defined in: src/persistence/DurableStateActor.ts:95

User handler — invoked once preStart has loaded the record.

Cmd

void | Promise<void>


onReceive(cmd): Promise<void>

Defined in: src/persistence/DurableStateActor.ts:89

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

Cmd

Promise<void>

Actor.onReceive


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>

Actor.postRestart


postStop(): void | Promise<void>

Defined in: src/Actor.ts:44

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

void | Promise<void>

Actor.postStop


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

Cmd

void | Promise<void>

Actor.preRestart


preStart(): Promise<void>

Defined in: src/persistence/DurableStateActor.ts:73

Called after construction and before the first message is processed.

Promise<void>

Actor.preStart


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

Actor.supervisorStrategy