EntityRef
Esta página aún no está disponible en tu idioma.
Defined in: src/cluster/sharding/EntityRef.ts:32
Location-transparent handle to a single sharded entity — the counterpart to the region ref, addressed by id rather than by whatever routing key your message type happens to carry.
Without it the region ref is the only handle sharding hands out, so every
message has to embed its own entity id for extractEntityId to dig back
out. An EntityRef wraps each message in a EntityEnvelope instead,
which the region routes by the id in the envelope — the message type itself
no longer has to know how it is routed.
Like ClusterSingletonProxy it extends ActorRef without being
backed by an actor of its own: it is a thin forwarder onto the local region,
which owns all the routing, buffering and cross-node machinery already.
ask therefore works unchanged — the region forwards the caller’s sender to
the entity, so a reply goes straight back without a detour.
The path is the entity’s path as it would be under this node’s region
(/system/cluster/sharding/region-<type>/shard-<n>/entity-<id>). It
identifies the entity —
two refs for the same (typeName, entityId) are equals() — but it does
not say which node currently hosts it; that can change on every rebalance,
which is the entire point of holding the handle instead of a path.
Extends
Section titled “Extends”ActorRef<TMessage>
Type Parameters
Section titled “Type Parameters”TMessage
Section titled “TMessage”TMessage = unknown
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new EntityRef<
TMessage>(region,typeName,entityId,numShards,systemName):EntityRef<TMessage>
Defined in: src/cluster/sharding/EntityRef.ts:35
Parameters
Section titled “Parameters”region
Section titled “region”ActorRef<unknown>
typeName
Section titled “typeName”string
entityId
Section titled “entityId”string
numShards
Section titled “numShards”number
systemName
Section titled “systemName”string
Returns
Section titled “Returns”EntityRef<TMessage>
Overrides
Section titled “Overrides”Properties
Section titled “Properties”entityId
Section titled “entityId”
readonlyentityId:string
Defined in: src/cluster/sharding/EntityRef.ts:38
readonlypath:ActorPath
Defined in: src/cluster/sharding/EntityRef.ts:33
Overrides
Section titled “Overrides”typeName
Section titled “typeName”
readonlytypeName:string
Defined in: src/cluster/sharding/EntityRef.ts:37
Methods
Section titled “Methods”ask<
TResponse>(message,timeoutMs?):Promise<TResponse>
Defined in: src/ActorRef.ts:77
Request/response — send message and await the recipient’s reply.
The framework synthesises a one-shot reply ref, injects it as both
the sender slot and as message.replyTo, and resolves the returned
promise with the first reply (or rejects with AskTimeoutError).
The caller never specifies replyTo on the message — the OmitReplyTo
type subtracts it from the parameter type if the recipient declares it.
const value = await counter.ask<number>({ kind: 'get' });Type Parameters
Section titled “Type Parameters”TResponse
Section titled “TResponse”TResponse = unknown
Parameters
Section titled “Parameters”message
Section titled “message”OmitReplyTo<TMessage>
timeoutMs?
Section titled “timeoutMs?”number = DEFAULT_ASK_TIMEOUT_MS
Returns
Section titled “Returns”Promise<TResponse>
Inherited from
Section titled “Inherited from”equals()
Section titled “equals()”equals(
other):boolean
Defined in: src/ActorRef.ts:104
Parameters
Section titled “Parameters”Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”kill()
Section titled “kill()”kill():
void
Defined in: src/ActorRef.ts:100
Kill this actor — raises ActorKilledError through the normal supervision path.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”send()
Section titled “send()”send(
message):void
Defined in: src/ActorRef.ts:64
Alias for tell — useful if you want to pipe something.
Parameters
Section titled “Parameters”message
Section titled “message”TMessage
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”stop()
Section titled “stop()”stop():
void
Defined in: src/ActorRef.ts:97
Gracefully stop this actor after it drains its mailbox.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”tell()
Section titled “tell()”tell(
message,sender?):void
Defined in: src/cluster/sharding/EntityRef.ts:50
Send a message to this actor. sender is surfaced as context.sender in the recipient.
Parameters
Section titled “Parameters”message
Section titled “message”TMessage
sender?
Section titled “sender?”ActorRef<unknown> | null
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”toString()
Section titled “toString()”toString():
string
Defined in: src/ActorRef.ts:102
Returns
Section titled “Returns”string
