ReactiveX / rxdart

The Reactive Extensions for Dart
http://reactivex.io
Apache License 2.0
3.37k stars 271 forks source link

When onErrorResumeNext is used, error do not cancel to listen previous stream #744

Closed rouddy closed 10 months ago

rouddy commented 10 months ago

When onErrorResumeNext is used, error do not cancel to listen previous stream.

here's test code

Rx.merge([
      Stream.periodic(const Duration(seconds: 1), (i) => i).map((event) => event + 1),
      Rx.concat([
        Rx.timer(1, const Duration(seconds: 5)),
        Stream.error(Exception("test"))
      ]).ignoreElements(),
    ])
        .asBroadcastStream()
        .doOnError((p0, p1) => print("!!!!! doOnError:$p0"))
        .onErrorResumeNext(Stream.periodic(const Duration(seconds: 1), (i) => i * 10))
        .listen((event) {
      print("!!!!! $event");
    }, onDone: () {
      print("!!!!! onDone");
    }, onError: (error, stacktrace) {
      print("!!!!! onError $error, $stacktrace");
    });

thanx

hoc081098 commented 10 months ago

This is the default behavior of Dart Stream. I think we should keep it

hoc081098 commented 10 months ago

The behavior you want to achieve can be implemented via an operator

https://pub.dev/documentation/rxdart_ext/latest/rxdart_ext/DoneOnErrorStreamExtension/doneOnError.html

rouddy commented 10 months ago

i understand about default behavior of dart stream. but stream offers cancelOnError option. And i think that 'resume' in 'onErrorResumeNext' means resuming next stream after previous stream pauses or stops.

but if i have alternative, i don't want to push ahead with my commit. i will close my pr.