ActorContext
Esta página aún no está disponible en tu idioma.
Defined in: src/ActorContext.ts:15
Runtime API given to every Actor. Access through this.context inside
an Actor subclass.
Type Parameters
Section titled “Type Parameters”TMsg = unknown
Properties
Section titled “Properties”children
Section titled “children”
readonlychildren: readonlyActorRef<unknown>[]
Defined in: src/ActorContext.ts:32
Snapshot of direct children.
readonlylog:Logger
Defined in: src/ActorContext.ts:35
Logger bound to this actor’s path.
parent
Section titled “parent”Defined in: src/ActorContext.ts:29
Parent actor, or None for the root guardian.
readonlypath:ActorPath
Defined in: src/ActorContext.ts:20
The ActorPath of this actor.
readonlyself:ActorRef<TMsg>
Defined in: src/ActorContext.ts:17
A reference to this actor.
sender
Section titled “sender”Defined in: src/ActorContext.ts:23
The sender of the message currently being processed, or None.
stashSize
Section titled “stashSize”
readonlystashSize:number
Defined in: src/ActorContext.ts:122
Number of currently-stashed messages.
system
Section titled “system”
readonlysystem:ActorSystem
Defined in: src/ActorContext.ts:26
The enclosing ActorSystem.
timers
Section titled “timers”
readonlytimers: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.
Methods
Section titled “Methods”actorSelection()
Section titled “actorSelection()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”become()
Section titled “become()”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().
Parameters
Section titled “Parameters”behavior
Section titled “behavior”Receive<TMsg>
discardOld?
Section titled “discardOld?”boolean
Returns
Section titled “Returns”void
cancelReceiveTimeout()
Section titled “cancelReceiveTimeout()”cancelReceiveTimeout():
void
Defined in: src/ActorContext.ts:104
Disable the receive timeout.
Returns
Section titled “Returns”void
cancelThrottle()
Section titled “cancelThrottle()”cancelThrottle():
void
Defined in: src/ActorContext.ts:152
Remove any active throttle, restoring unlimited dequeue rate.
Returns
Section titled “Returns”void
child()
Section titled “child()”Defined in: src/ActorContext.ts:68
Look up a direct child by name. None if no such child exists.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”setReceiveTimeout()
Section titled “setReceiveTimeout()”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.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
spawn()
Section titled “spawn()”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”Props<T>
string
Returns
Section titled “Returns”ActorRef<T>
spawnAnonymous()
Section titled “spawnAnonymous()”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”Props<T>
Returns
Section titled “Returns”ActorRef<T>
spawnTyped()
Section titled “spawnTyped()”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');Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”behavior
Section titled “behavior”Behavior<T>
string
Returns
Section titled “Returns”ActorRef<T>
spawnTypedAnonymous()
Section titled “spawnTypedAnonymous()”spawnTypedAnonymous<
T>(behavior):ActorRef<T>
Defined in: src/ActorContext.ts:65
Anonymous variant of spawnTyped — the Behavior-DSL counterpart to spawnAnonymous.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”behavior
Section titled “behavior”Behavior<T>
Returns
Section titled “Returns”ActorRef<T>
stash()
Section titled “stash()”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.
Returns
Section titled “Returns”void
stop()
Section titled “stop()”stop(
ref):void
Defined in: src/ActorContext.ts:77
Ask the runtime to stop the given actor. Equivalent to ref.stop().
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
stopSelf()
Section titled “stopSelf()”stopSelf():
void
Defined in: src/ActorContext.ts:80
Stop this actor itself.
Returns
Section titled “Returns”void
throttle()
Section titled “throttle()”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.
Parameters
Section titled “Parameters”ThrottleOptions
Returns
Section titled “Returns”void
unbecome()
Section titled “unbecome()”unbecome():
void
Defined in: src/ActorContext.ts:95
Pop the behaviour stack, restoring the previous behaviour.
Returns
Section titled “Returns”void
unstashAll()
Section titled “unstashAll()”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.
Returns
Section titled “Returns”void
unwatch()
Section titled “unwatch()”unwatch(
ref):ActorRef
Defined in: src/ActorContext.ts:86
Stop watching.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”watch()
Section titled “watch()”watch(
ref):ActorRef
Defined in: src/ActorContext.ts:83
Start death-watching an actor. A Terminated message is sent when it stops.