Aller au contenu
Français

ActorContext

Ce contenu n’est pas encore disponible dans votre langue.

Defined in: src/ActorContext.ts:15

Runtime API given to every Actor. Access through this.context inside an Actor subclass.

TMsg = unknown

readonly children: readonly ActorRef<unknown>[]

Defined in: src/ActorContext.ts:32

Snapshot of direct children.


readonly log: Logger

Defined in: src/ActorContext.ts:35

Logger bound to this actor’s path.


readonly parent: Option<ActorRef<unknown>>

Defined in: src/ActorContext.ts:29

Parent actor, or None for the root guardian.


readonly path: ActorPath

Defined in: src/ActorContext.ts:20

The ActorPath of this actor.


readonly self: ActorRef<TMsg>

Defined in: src/ActorContext.ts:17

A reference to this actor.


readonly sender: Option<ActorRef<unknown>>

Defined in: src/ActorContext.ts:23

The sender of the message currently being processed, or None.


readonly stashSize: number

Defined in: src/ActorContext.ts:122

Number of currently-stashed messages.


readonly system: ActorSystem

Defined in: src/ActorContext.ts:26

The enclosing ActorSystem.


readonly timers: TimerScheduler<TMsg>

Defined in: src/ActorContext.ts:130

Per-actor scheduling facade. Timers are identified by user-supplied string keys and are automatically cancelled when the actor stops.

actorSelection(path): ActorSelection

Defined in: src/ActorContext.ts:74

Build an ActorSelection that resolves a full-path lookup. Delegates to the enclosing ActorSystem — same semantics as system.actorSelection.

string

ActorSelection


become(behavior, discardOld?): void

Defined in: src/ActorContext.ts:92

Replace the current behaviour. When discardOld is false, the previous behaviour is pushed onto a stack and can be restored via unbecome().

Receive<TMsg>

boolean

void


cancelReceiveTimeout(): void

Defined in: src/ActorContext.ts:104

Disable the receive timeout.

void


cancelThrottle(): void

Defined in: src/ActorContext.ts:152

Remove any active throttle, restoring unlimited dequeue rate.

void


child(name): Option<ActorRef<unknown>>

Defined in: src/ActorContext.ts:68

Look up a direct child by name. None if no such child exists.

string

Option<ActorRef<unknown>>


setReceiveTimeout(ms): void

Defined in: src/ActorContext.ts:101

Fire a ReceiveTimeout message when no user message has been received in ms. Pass 0 to disable.

number

void


spawn<T>(props, name): ActorRef<T>

Defined in: src/ActorContext.ts:42

Spawn a child actor under this one with a deterministic caller-supplied name. The name must be unique among siblings. For an auto-generated name, see spawnAnonymous.

T

Props<T>

string

ActorRef<T>


spawnAnonymous<T>(props): ActorRef<T>

Defined in: src/ActorContext.ts:50

Spawn a child actor under this one with an auto-generated name. Useful for one-shot helpers and other transient children where the caller doesn’t need a stable path. For a deterministic name, see spawn.

T

Props<T>

ActorRef<T>


spawnTyped<T>(behavior, name): ActorRef<T>

Defined in: src/ActorContext.ts:59

Spawn a typed-Behavior child with a deterministic name — the Behavior-DSL counterpart to spawn. Wraps the Behavior in typedProps internally so callers don’t have to.

const child = this.context.spawnTyped(counter(0), 'counter');

T

Behavior<T>

string

ActorRef<T>


spawnTypedAnonymous<T>(behavior): ActorRef<T>

Defined in: src/ActorContext.ts:65

Anonymous variant of spawnTyped — the Behavior-DSL counterpart to spawnAnonymous.

T

Behavior<T>

ActorRef<T>


stash(): void

Defined in: src/ActorContext.ts:113

Buffer the message currently being handled. It is reinserted into the mailbox when unstashAll() is called. Throws if called outside a user-message handler or if the stash is full.

void


stop(ref): void

Defined in: src/ActorContext.ts:77

Ask the runtime to stop the given actor. Equivalent to ref.stop().

ActorRef

void


stopSelf(): void

Defined in: src/ActorContext.ts:80

Stop this actor itself.

void


throttle(opts): void

Defined in: src/ActorContext.ts:149

Throttle this actor’s user-message processing to a token-bucket rate (#83). Every dequeue from the user mailbox consumes one token; when the bucket is empty the cell behaves per ThrottleOnExcess. System messages (Terminated, supervision, watchNotify) are NOT throttled — they always run immediately, so timer fires and lifecycle events stay responsive.

Calling throttle again replaces the existing limiter; pass { qps: Infinity } or call cancelThrottle to remove one.

Cluster-aware variants (split a budget across cluster-router routees, etc.) are out of scope here — this is per-actor only.

ThrottleOptions

void


unbecome(): void

Defined in: src/ActorContext.ts:95

Pop the behaviour stack, restoring the previous behaviour.

void


unstashAll(): void

Defined in: src/ActorContext.ts:119

Prepend every stashed message back onto the user mailbox in the order they were stashed. The buffer is empty afterwards.

void


unwatch(ref): ActorRef

Defined in: src/ActorContext.ts:86

Stop watching.

ActorRef

ActorRef


watch(ref): ActorRef

Defined in: src/ActorContext.ts:83

Start death-watching an actor. A Terminated message is sent when it stops.

ActorRef

ActorRef