Skip to Content
Mastering PHP 7
book

Mastering PHP 7

by Branko Ajzele
June 2017
Intermediate to advanced
536 pages
9h 49m
English
Packt Publishing
Content preview from Mastering PHP 7

Observables and event loop 

Let's go ahead and see how we can make our observables work with an event loop:

<?phprequire_once __DIR__ . '/vendor/autoload.php';use \React\EventLoop\Factory;use \Rx\Scheduler;use \Rx\Observable;use \Rx\Subject\Subject;use \Rx\Scheduler\EventLoopScheduler;$loop = Factory::create();Scheduler::setDefaultFactory(function () use ($loop) {    return new Scheduler\EventLoopScheduler($loop);});$stdin = fopen('php://stdin', 'r');stream_set_blocking($stdin, 0);$observer = new class() extends Subject{    public function onCompleted()    {        echo '$observer.onCompleted: ', PHP_EOL;        parent::onCompleted();    }    public function onNext($val)    {        echo '$observer.onNext: ', $val, PHP_EOL;        parent::onNext($val);    }    public function onError(\Throwable ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning PHP 7

Learning PHP 7

Antonio L Zapata (GBP)
Upgrading to PHP 5

Upgrading to PHP 5

Adam Trachtenberg

Publisher Resources

ISBN: 9781785882814Supplemental Content