SingletonKey
Este conteúdo não está disponível em sua língua ainda.
Defined in: src/cluster/singleton/SingletonKey.ts:29
Named, type-tagged identity for a cluster singleton — the singleton
counterpart to ServiceKey. Two keys are equal iff their typeName
matches; the type parameter is a compile-time marker that lets start() and
ref() hand back a correctly-typed ActorRef without the caller repeating
the message type at every site.
The field is typeName, not id, because it is the same string that feeds
singletonManagerName and the wire-visible manager path — a second name for
it would be drift waiting to happen.
class JobSchedulerActor extends Actor<SchedulerCommand> { static readonly singleton = SingletonKey.of<SchedulerCommand>('job-scheduler');}
// Restricted to nodes carrying a role — declared once, read by every node.class IngressActor extends Actor<IngressCommand> { static readonly singleton = SingletonKey.of<IngressCommand>('http-ingress', 'edge');}The explicit type argument is load-bearing: SingletonKey.of('job-scheduler')
infers SingletonKey<unknown>, which degrades every start() / ref() that
uses it to ActorRef<unknown>.
Type Parameters
Section titled “Type Parameters”TCommand
Section titled “TCommand”TCommand = unknown
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SingletonKey<
TCommand>(typeName,role?):SingletonKey<TCommand>
Defined in: src/cluster/singleton/SingletonKey.ts:33
Parameters
Section titled “Parameters”typeName
Section titled “typeName”string
string
Restrict hosting to nodes carrying this role.
It rides along on the key — like ShardKey’s extractEntityId —
so the declaring class is the single source of truth, and it is NOT part
of the identity: equals ignores it. A role in
StartSingletonOptions wins over this one.
The key is where it has to live for a proxy to be right. Both the
hosting node and a node that only calls ref() have to resolve the same
host, and a ref()-only node has no options object to read it from — it
has the key, and nothing else. Declared here, both sides agree by
construction.
Returns
Section titled “Returns”SingletonKey<TCommand>
Properties
Section titled “Properties”_command
Section titled “_command”
readonly_command:TCommand
Defined in: src/cluster/singleton/SingletonKey.ts:31
Phantom field — retains TCommand so inference round-trips through the key.
readonlyoptionalrole?:string
Defined in: src/cluster/singleton/SingletonKey.ts:49
Restrict hosting to nodes carrying this role.
It rides along on the key — like ShardKey’s extractEntityId —
so the declaring class is the single source of truth, and it is NOT part
of the identity: equals ignores it. A role in
StartSingletonOptions wins over this one.
The key is where it has to live for a proxy to be right. Both the
hosting node and a node that only calls ref() have to resolve the same
host, and a ref()-only node has no options object to read it from — it
has the key, and nothing else. Declared here, both sides agree by
construction.
typeName
Section titled “typeName”
readonlytypeName:string
Defined in: src/cluster/singleton/SingletonKey.ts:34
Methods
Section titled “Methods”equals()
Section titled “equals()”equals(
other):boolean
Defined in: src/cluster/singleton/SingletonKey.ts:56
Parameters
Section titled “Parameters”SingletonKey
Returns
Section titled “Returns”boolean
toString()
Section titled “toString()”toString():
string
Defined in: src/cluster/singleton/SingletonKey.ts:57
Returns
Section titled “Returns”string
staticof<TCommand>(typeName,role?):SingletonKey<TCommand>
Defined in: src/cluster/singleton/SingletonKey.ts:52
Type Parameters
Section titled “Type Parameters”TCommand
Section titled “TCommand”TCommand
Parameters
Section titled “Parameters”typeName
Section titled “typeName”string
string
Returns
Section titled “Returns”SingletonKey<TCommand>
