advanceToNext method

Future<Duration?> advanceToNext()

Moves time forward to the next pending delay, completing it.

Returns the amount of time that passed, or null when nothing was pending. Use it to step through a schedule one wait at a time.

Implementation

Future<Duration?> advanceToNext() async {
  if (_pending.isEmpty) return null;
  _pending.sort((a, b) => a.dueAt.compareTo(b.dueAt));
  final elapsed = _pending.first.dueAt.difference(_now);
  await advance(elapsed);
  return elapsed;
}