Creates a generator object with the default random number generator, or with the specified one if passed as an argument. The specified random number generator should be cryptographically strong and securely seeded.
Generates a new SCRU128 ID object from the current timestamp
, or resets
the generator upon significant timestamp rollback.
See the Scru128Generator class documentation for the description.
Generates a new SCRU128 ID object from the current timestamp
, or returns
undefined
upon significant timestamp rollback.
See the Scru128Generator class documentation for the description.
Generates a new SCRU128 ID object from the timestamp
passed, or returns
undefined
upon significant timestamp rollback.
See the Scru128Generator class documentation for the description.
The amount of timestamp
rollback that is
considered significant. A suggested value is 10_000
(milliseconds).
Generates a new SCRU128 ID object from the timestamp
passed, or resets
the generator upon significant timestamp rollback.
See the Scru128Generator class documentation for the description.
The amount of timestamp
rollback that is
considered significant. A suggested value is 10_000
(milliseconds).
Returns a new SCRU128 ID object for each call, infinitely.
This method wraps the result of generate in an IteratorResult
object to use this
as an infinite iterator.
Represents a SCRU128 ID generator that encapsulates the monotonic counters and other internal states.
Example
Remarks
The generator comes with four different methods that generate a SCRU128 ID:
undefined
undefined
All of the four return a monotonically increasing ID by reusing the previous
timestamp
even if the one provided is smaller than the immediately preceding ID's. However, when such a clock rollback is considered significant (by default, more than ten seconds):generate
(OrReset) methods reset the generator and return a new ID based on the giventimestamp
, breaking the increasing order of IDs.OrAbort
variants abort and returnundefined
immediately.The
Core
functions offer low-level primitives to customize the behavior.