retry<T> static method

Stream<T> retry<T>(
  1. Stream<T> streamFactory(), [
  2. int? count
])

Creates a Stream that will recreate and re-listen to the source Stream the specified number of times until the Stream terminates successfully.

If the retry count is not specified, it retries indefinitely. If the retry count is met, but the Stream has not terminated successfully, all of the errors and StackTraces that caused the failure will be emitted.

Example

Rx.retry(() => Stream.value(1))
    .listen((i) => print(i)); // Prints 1

Rx.retry(
  () => Stream.value(1).concatWith([Stream<int>.error(Error())]),
  1,
).listen(
  print,
  onError: (Object e, StackTrace s) => print(e),
); // Prints 1, 1, Instance of 'Error', Instance of 'Error'

Implementation

static Stream<T> retry<T>(Stream<T> Function() streamFactory, [int? count]) =>
    RetryStream<T>(streamFactory, count);