StreamErrorRecovery<T> extension


Stream Error Recovery Extensions

Provides error recovery strategies on Stream, including retry logic with exponential backoff and alternative recovery modes.

The following methods are available:

  • retry: Resubscribes to the source stream when an error occurs, up to a maximum number of attempts.
  • replaceOnError: Replaces an error event with a provided default value, then completes.
  • completeOnError: Completes the stream immediately upon an error.

Example:

// Retry up to 3 times with an initial delay of 1 second.
myStream.retry(retryCount: 3, delayFactor: Duration(seconds: 1))
  .listen(print, onError: print);
on

Methods

completeOnError() Stream<T>

Available on Stream<T>, provided by the StreamErrorRecovery extension

Completes the stream immediately upon an error, swallowing the error.
replaceOnError({required T defaultValue}) Stream<T>

Available on Stream<T>, provided by the StreamErrorRecovery extension

Replaces an error event with defaultValue and then completes the stream.
retry({int retryCount = 3, Duration delayFactor = const Duration(seconds: 1), bool shouldRetry(Object error)?}) Stream<T>

Available on Stream<T>, provided by the StreamErrorRecovery extension

Retries the stream subscription in case of error.