Handling error states in operator chains
If we go back to
Chapter 2
, Reactive Programming with RxPHP, and CURLObservable
, we know that it emits onError
when it wasn't able to download any data. The question is, what if we want to try downloading the URL again? And even more interestingly, repeat the failed attempt every few seconds.
Subscribing only to onError
signals is simple with the second parameter to the subscribeCallback()
method:
(new CURLObservable('https://example.com')) ->subscribeCallback(null, function($e) { ... });
It's obvious that nesting another CURLObservable
into onError
handler is probably not an option. This is exactly what the retry()
operator is designed for.
The retry() operator
When the retry()
operator receives an onError
signal, it captures it and tries to resubscribe to its source Observable. It takes as an argument the number of times it tries to resubscribe until it passes the error signal down...