Creates a new generator with the given node configuration and counter mode.
Optional counterMode: CounterModeSyntaxError if an invalid string nodeSpec is passed or
RangeError if an invalid object nodeSpec is passed.
Private Readonly counterPrivate Readonly counterPrivate prevPrivate prevGenerates a new SCRU64 ID object from the current timestamp, or returns
undefined upon significant timestamp rollback.
See the Scru64Generator class documentation for the description.
Generates a new SCRU64 ID object from a Unix timestamp in milliseconds, or
returns undefined upon significant timestamp rollback.
See the Scru64Generator class documentation for the description.
The amount of unixTsMs rollback that is
considered significant. A suggested value is 10_000 (milliseconds).
RangeError if unixTsMs is not a positive integer within the valid
range.
Returns a new SCRU64 ID object, or asynchronously sleeps and waits for one if not immediately available.
See the Scru64Generator class documentation for the description.
Generates a new SCRU64 ID object from the current timestamp, or resets
the generator upon significant timestamp rollback.
See the Scru64Generator class documentation for the description.
Note that this mode of generation is not recommended because rewinding
timestamp without changing nodeId considerably increases the risk of
duplicate results.
Generates a new SCRU64 ID object from a Unix timestamp in milliseconds, or resets the generator upon significant timestamp rollback.
See the Scru64Generator class documentation for the description.
Note that this mode of generation is not recommended because rewinding
timestamp without changing nodeId considerably increases the risk of
duplicate results.
The amount of unixTsMs rollback that is
considered significant. A suggested value is 10_000 (milliseconds).
RangeError if unixTsMs is not a positive integer within the valid
range.
Returns a new SCRU64 ID object, or synchronously sleeps and waits for one if not immediately available.
See the Scru64Generator class documentation for the description.
This method uses a blocking busy loop to wait for the next timestamp
tick. Use generateOrAwait where possible.
Private renew
Represents a SCRU64 ID generator.
The generator comes with several different methods that generate a SCRU64 ID:
undefinedundefinedAll of these methods return a monotonically increasing ID by reusing the previous
timestampeven if the one provided is smaller than the immediately preceding ID's, unless such a clock rollback is considered significant (by default, approx. 10 seconds). A clock rollback may also be detected when a generator has generated too many IDs within a certain unit of time, because this implementation increments the previoustimestampwhencounterreaches the limit to continue instant monotonic generation. When a significant clock rollback is detected:generate(OrAbort) methods abort and returnundefinedimmediately.OrResetvariants reset the generator and return a new ID based on the giventimestamp, breaking the increasing order of IDs.OrSleepandOrAwaitmethods sleep and wait for the next timestamp tick.The
Corefunctions offer low-level primitives to customize the behavior.