Observable::create() and Observable::defer()
We know how to create Observables using ReturnObservable
or RangeObservable
. We've also written a custom CURLObservable
as well. However, in some situations we might want to create an Observable with some custom logic that isn't easily reproducible with already existing Observable classes. Of course, we could write another Observable inheriting the base Observable class, but if we need to deal with a very specific, single use-case scenario, there's an easier way with static methods Observable::create()
and Observable::defer()
.
Creating Observables with Observable::create()
With Observable::create()
, we can create an Observable that automatically pushes values into each of its observers on subscription. Consider the following example:
// observable_create_01.php use Rx\Observable; use Rx\ObserverInterface; $source = Observable::create(function(ObserverInterface $obs) { echo "Observable::create\n"; $obs->...