start method

void start(
  1. String key,
  2. Duration duration
)

Starts (or restarts, if already running) the cooldown at key to end duration from now. Persists immediately (not write-behind-buffered) — a missed write on kill here would let a booster/reward be reused for free, the same "real transaction" class as a purchase.

Implementation

void start(String key, Duration duration) {
  if (key.isEmpty) {
    throw ArgumentError.value(key, 'key', 'must not be empty');
  }
  if (duration <= Duration.zero) {
    throw ArgumentError.value(duration, 'duration', 'must be > 0');
  }
  final state = _readState();
  state[key] = nowMsClamped() + duration.inMilliseconds;
  _persist(state);
  revision.value++;
}