- T returnFn(
- dynamic error
instructs a Stream to emit a particular item created by the
returnFn when it encounters an error, and then terminate normally.
The onErrorReturnWith operator intercepts an onError notification from the source Stream. Instead of passing it through to any observers, it replaces it with a given item, and then terminates normally.
returnFn receives the emitted error and returns a Stream. You can
perform logic in the
returnFn to return different Streams based on the
type of error that was emitted.
If you do not need to perform logic based on the type of error that was
emitted, please consider using
ErrorStream(Exception()) .onErrorReturnWith((e) => e is Exception ? 1 : 0) .listen(print); // prints 1
Stream<T> onErrorReturnWith(T Function(dynamic error) returnFn) => transform(OnErrorResumeStreamTransformer<T>( (dynamic e) => Stream.value(returnFn(e))));