Error handling in RxPHP operator chains
You may be wondering why we can't just emit multiple errors from an Observable and then use materialize()
to wrap them.
Consider the following example with Observable::create
that emits two errors:
// materialize_05.php Observable::create(function($observer) { $observer->onNext(1); $observer->onNext(2); $observer->onError(new Exception()); $observer->onNext(4); $observer->onError(new Exception()); $observer->onNext(6); }) ->materialize() ->subscribe(new DebugSubject());
It might look like this example should wrap all the values and errors into notifications because we put the materialize()
operator right after the Observable::create
. Let's see what happens when we run this:
$ php materialize_05.php 21:14:53 [] onNext: OnNext(1) (Rx\Notification\OnNextNotification) 21:14:53 [] onNext: OnNext(2) (Rx\Notification\OnNextNotification)...