These are chat archives for ReactiveX/RxJava

25th
May 2018
Alexandru Nedelcu
@alexandru
May 25 2018 08:03
Hi all, quick question — is the concatMap on Single stack safe?
David Karnok
@akarnokd
May 25 2018 09:14
What do you mean by that?
Rishabh Harit
@rishabh876
May 25 2018 09:38
So I am using RxJava with Retrofit and I was wondering if it would be a good idea to use RxJavaPlugin. setErrorHandler(), which is a global level error handler, for something like access token expired errors in api. As this kind of error is also not api specific but applies to all apis. So handling such error needs be at a global level.
David Karnok
@akarnokd
May 25 2018 09:52
setErrorHandler is for undeliverable errors that can't be emitted through the regular onError channel of a flow. Setting it prevents crashes on Android. I'd assume token failures would be reported through onError pretty reliably so the handler wouldn't even be called.
Rishabh Harit
@rishabh876
May 25 2018 09:53
Yeah but for my case I wont call the onError(throwable) of Emitter. I would rather be doing RxJavaPlugin.onError(throwable)
David Karnok
@akarnokd
May 25 2018 10:14
Do you otherwise complete the emitter in some way? Because if not, that would keep the flow hanging waiting for a terminal signal.
Alexandru Nedelcu
@alexandru
May 25 2018 11:53

@akarnokd

Single<Integer> loop(int n, int acc) {
  return n > 0
    ? Single.just(acc).flatMap(x => loop(n - 1, acc + 1))
    : Single.just(acc)
}

I mean, is this loop using constant memory? I'm not at my laptop to be able to check.

David Karnok
@akarnokd
May 25 2018 11:55
No, you'll end up with stackoverflow that way.
Alexandru Nedelcu
@alexandru
May 25 2018 11:56
Cool, thanks. Had a curiosity.
Rishabh Harit
@rishabh876
May 25 2018 15:56
@akarnokd I would call the onError of Emitter as well then. But the question I want to ask, is this a good way to handle such error. I somehow feel this is what it was made for.
David Karnok
@akarnokd
May 25 2018 17:12
It was not meant for that. For this purpose, you could just introduce another global callback in your application.