delay function

Future<void> delay(
  1. Duration duration
)

Wait for the duration specified in duration.

This is not the same as sleep. This function does not block any asynchronous operations in the current Isolate.

Implementation

Future<void> delay(Duration duration) {
  // Inform user if they provided a strange [duration].
  //
  // There is no need to throw, becaue [Future.delayed] also works with
  // negative durations.
  assert(
    duration.isPositive,
    "Delaying for a negative amount of time makes no sense.",
  );

  return Future.delayed(duration);
}