RxSwiftCommunity / RxSwiftExt

A collection of Rx operators & tools not found in the core RxSwift distribution
MIT License
1.33k stars 213 forks source link

Name of method `ignoreErrors` break contract of `PublishSubject` #217

Open ajjnix opened 5 years ago

ajjnix commented 5 years ago

PublishSubject is not working with ignoreErrors function because ignoreErrors is synonym of retry. But PublishSubject can't retry by contract cause it's not operation.

        let subject = PublishSubject<Int>()
        _ = subject.ignoreErrors().subscribe(onNext: {
            print($0)
        })
        subject.onNext(1)
        subject.onError(RxError.unknown)
        subject.onNext(2)
        subject.onNext(3)

// output: INFINIRY_LOOP

In this code I can think the sequence can't terminated on error (and yes it's not terminated 😺) but it's not right by contract of Observable. So I think this operator is mislead and I suggest to remove it.

freak4pc commented 5 years ago

You can't technically do anything against the contract.

The stream isn't terminated because ignoreErrors is just an alias to retry - by infinitely retrying the error'd stream, you are stuck in an infinite loop.

What we can do is change the documentation perhaps. I also think the naming is a bit misleading, because you're not exactly ignoring errors. Ignoring errors would be something like materialize, filtering errors and dematerialize.

@fpillet your thoughts?