randomId
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
randomId(
length,exists?):string
Defined in: src/util/RandomString.ts:148
length random characters for something the framework has to name itself.
Such a name ends up in an actor path, and a path is an address: on the cluster
wire anything that can render one can send to it. A counter makes that
address guessable — knowing one hands you the next — which is why ask’s
reply refs and anonymous actors both draw from here. Twelve hex characters
are ~48 bits, far past the number of names either site has live at once, which
is the only uniqueness that has to hold.
Hex rather than the full alphanumeric range, even though nothing mandates it
here the way traceparent does for randomHex: these names are read far
more often than they are typed — a log line, a DevTools row, a grep — and one
case with no letter/digit lookalikes reads better there than the extra bits per
character are worth. Kept distinct from randomHex so that reasoning stays
local: this one names a purpose and could change alphabet, that one names an
external constraint and cannot.
exists is the optional collision check every helper here takes, and is the
one an actor name is most likely to want: sibling names have to be unique
under a parent, which ~48 bits make overwhelmingly likely but not certain.
The delegation to randomHex deliberately forwards no predicate of its
own. randomHex would then run a second bounded retry inside this one,
making the effective budget 1 000 × 1 000 and putting the wrong helper’s name
in the error — the retry belongs to the call the caller actually made.
Parameters
Section titled “Parameters”length
Section titled “length”number
exists?
Section titled “exists?”Returns
Section titled “Returns”string
