TidGenerator.withClockId constructor

TidGenerator.withClockId(
  1. int clockId, {
  2. int now()?,
})

Returns a generator with an explicit clockId and an optional now, both injectable so tests are deterministic.

clockId is masked to _clockIdBits bits, so an out-of-range value cannot corrupt the timestamp. now returns microseconds since the UNIX epoch and defaults to the system clock.

Implementation

TidGenerator.withClockId(final int clockId, {final int Function()? now})
  : _clockId = clockId & ((1 << _clockIdBits) - 1),
    _now = now ?? _systemNow;