withInitialDelay method

Stream<T> withInitialDelay(
  1. Duration minOperationTime, {
  2. Duration threshold = const Duration(milliseconds: 50),
})

If the time it takes for the first event to appear is less than minOperationTime, then a Future.delayed is awaited for the remaining time. withInitialDelay only affects the first event of this Stream. The delay also affects any errors of this Stream.

The Stream returned by this method will take at least as much time as specified by minOperationTime to complete.

When a subscription on the returned Stream is paused, then the internal stopwatch that is used to check if minOperationTime has already passed, will also be stopped. Resuming the subscription starts the watch again.

Implementation

Stream<T> withInitialDelay(
  Duration minOperationTime, {
  Duration threshold = const Duration(milliseconds: 50),
}) {
  return transform(
    InitialDelayStreamTransformer(
      minOperationTime: minOperationTime,
      threshold: threshold,
    ),
  );
}