-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Are there any build in observers for invoking action if onError or onNext was called? #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Probably we can add additional variation of doOnEach. Like doOnNextOrError? |
There are already options for this:
You can put these in the sequence wherever you want (before/after whichever sequence of the chain). |
@benjchristensen so right now Im using doOnEach with my custom observer. There is no doOnNextOrError that I need. Do you thinks its reasonable to have this overload in framework? I can implement it and make a pull request. |
There is a doOnEach that takes actions for onNext and onError. I don't understand how that is different than a doOnNextOrOnError. |
@benjchristensen difference is that i need to run same logic in both onNext and onError. If I will use onNext and onError i will need to call ProgressDialogFragment.dismiss() in each of them. |
Why is that an issue to call it in either of them? You can pass the same function to both the |
@benjchristensen The only problem is that It's very frequent use case. So code like this will be repeated very often: api.doOnEach(actionOnNextOrError, actionOnNextOrError) |
It's not appropriate to do both onNext and onError with the same function as they receive different argument types. OnNext receives type T, onError receives Throwable. Thus your use case is unique in ignoring either argument. The onEach operator is not the right place to combine these. It sounds like you want something like finallyDo for terminal state (after onComplete or onError) but before instead of after. |
@benjchristensen You are right. I actually used finallyDo before. But in mine specific use case I realized that I cannot use finallyDo since the code should be executed before onNext and onError. So you think that should be another operator with name like beforeDo? Or its not a generic case and my approach with NextOrErrorObserver is fine:
|
@benjchristensen I ended with using this custom class, which I can supply as an argument to doOnEach
|
I think your use of |
…asure met… (ReactiveX#556) * Issue ReactiveX#547: Added a Sliding Time Window implementations to measure metrics. * Issue ReactiveX#547: Added a Fixed size Sliding Window implementation which aggregates the last N calls and replaced the existing RingBitSet.
Are there any build in observers for invoking action if onError or onNext was called?
Typical use case is rest call from UI. Before REST call you should disable inteface and if operation success or fails you should reenable it again.
Currently I implemented one by my self.
BTW: I cannot use finallyDo for this. Finally do only triggered for onComplete and onError. Also I need my method to be called before onNext and onError.
The text was updated successfully, but these errors were encountered: