backoff method

FutureOr<void> backoff(
  1. int i, {
  2. required List<int> schedule,
})

Returns a future that completes after schedule[i] milliseconds. If i is out of range, the future completes in schedule.last milliseconds or immediately when schedule is empty.

Implementation

FutureOr<void> backoff(final int i, { required final List<int> schedule }) {
  final int delayMs = i < schedule.length ? schedule[i] : (schedule.isEmpty ? 0 : schedule.last);
  return delayMs > 0 ? Future.delayed(Duration(milliseconds: delayMs)) : null;
}