Esempio n. 1
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = \React\EventLoop\Factory::create();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$count = 0;
$observable = Rx\Observable::interval(1000, $scheduler)->flatMap(function ($x) use(&$count) {
    if (++$count < 2) {
        return Rx\Observable::error(new \Exception("Something"));
    }
    return Rx\Observable::just(42);
})->retry(3)->take(1);
$observable->subscribe($stdoutObserver);
$loop->run();
Esempio n. 2
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = React\EventLoop\Factory::create();
$scheduler = new Rx\Scheduler\EventLoopScheduler($loop);
$observable = Rx\Observable::just(42)->repeat();
$otherObservable = Rx\Observable::just(21)->repeat();
$mergedObservable = $observable->merge($otherObservable, $scheduler)->take(10);
$disposable = $mergedObservable->subscribe($stdoutObserver, $scheduler);
$loop->run();
//Next value: 42
//Next value: 21
//Next value: 42
//Next value: 21
//Next value: 42
//Next value: 21
//Next value: 42
//Next value: 21
//Current memory usage: 838.547K
Esempio n. 3
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$obs2 = Rx\Observable::just(42);
$source = \Rx\Observable::error(new Exception("Some error"))->catchError(function (Exception $e, \Rx\Observable $sourceObs) use($obs2) {
    return $obs2;
});
$subscription = $source->subscribe($stdoutObserver);
Esempio n. 4
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = \React\EventLoop\Factory::create();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$source = Rx\Observable::just(42)->repeatWhen(function (\Rx\Observable $notifications) {
    return $notifications->scan(function ($acc, $x) {
        return $acc + $x;
    }, 0)->delay(1000)->doOnNext(function () {
        echo "1 second delay", PHP_EOL;
    })->takeWhile(function ($count) {
        return $count < 2;
    });
});
$subscription = $source->subscribe($createStdoutObserver(), $scheduler);
$loop->run();
Esempio n. 5
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = \React\EventLoop\Factory::create();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$interval = Rx\Observable::interval(1000);
$source = $interval->take(4)->doOnNext(function ($x) {
    echo 'Side effect', PHP_EOL;
});
$published = $source->shareReplay(3);
$published->subscribe($createStdoutObserver('SourceA '), $scheduler);
$published->subscribe($createStdoutObserver('SourceB '), $scheduler);
Rx\Observable::just(true)->concatMapTo(\Rx\Observable::timer(6000))->flatMap(function () use($published) {
    return $published;
})->subscribe($createStdoutObserver('SourceC '), $scheduler);
$loop->run();