Exemple #1
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = \React\EventLoop\Factory::create();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$observable = Rx\Observable::interval(1000)->skipUntil(\Rx\Observable::timer(5000))->take(3);
$observable->subscribe($stdoutObserver, $scheduler);
$loop->run();
Exemple #2
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = new \React\EventLoop\StreamSelectLoop();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
Rx\Observable::interval(1000)->timeout(500)->subscribe($createStdoutObserver("One second - "), $scheduler);
Rx\Observable::interval(100)->take(3)->timeout(500)->subscribe($createStdoutObserver("100 ms     - "), $scheduler);
$loop->run();
// Output:
//100 ms     - Next value: 0
//100 ms     - Next value: 1
//100 ms     - Next value: 2
//100 ms     - Complete!
//One second - Exception: timeout
Exemple #3
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = new \React\EventLoop\StreamSelectLoop();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$source = Rx\Observable::interval(1000)->map(function ($n) {
    if ($n === 2) {
        throw new Exception();
    }
    return $n;
})->retryWhen(function ($errors) {
    return $errors->delay(200);
})->take(6);
$subscription = $source->subscribe($createStdoutObserver(), $scheduler);
$loop->run();
Exemple #4
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();
Exemple #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();