Exemplo n.º 1
0
<?php

use Rx\Observer\CallbackObserver;
require_once __DIR__ . '/../bootstrap.php';
$loop = \React\EventLoop\Factory::create();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$codes = [['id' => 38], ['id' => 38], ['id' => 40], ['id' => 40], ['id' => 37], ['id' => 39], ['id' => 37], ['id' => 39], ['id' => 66], ['id' => 65]];
$source = Rx\Observable::fromArray($codes)->concatMap(function ($x) {
    return \Rx\Observable::timer(100)->mapTo($x);
})->groupByUntil(function ($x) {
    return $x['id'];
}, function ($x) {
    return $x['id'];
}, function ($x) {
    return Rx\Observable::timer(200);
});
$subscription = $source->subscribe(new CallbackObserver(function (\Rx\Observable $obs) {
    // Print the count
    $obs->count()->subscribe(new CallbackObserver(function ($x) {
        echo 'Count: ', $x, PHP_EOL;
    }));
}, function (Exception $err) {
    echo 'Error', $err->getMessage(), PHP_EOL;
}, function () {
    echo 'Completed', PHP_EOL;
}), $scheduler);
$loop->run();
Exemplo n.º 2
0
<?php

require_once __DIR__ . '/../bootstrap.php';
use Rx\Observable\ArrayObservable;
$observable = Rx\Observable::fromArray([1, 1, 2, 3, 5, 8, 13]);
$observable->skip(3)->subscribe($stdoutObserver);
Exemplo n.º 3
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$observable = Rx\Observable::fromArray([21, 42, 84]);
$observable->filter(function ($elem) {
    return $elem >= 42;
})->subscribe($stdoutObserver);
Exemplo n.º 4
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$subscriptions = Rx\Observable::fromArray([21, 42])->mapWithIndex(function ($index, $elem) {
    return $index + $elem;
})->subscribe($stdoutObserver);
Exemplo n.º 5
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = \React\EventLoop\Factory::create();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$source = Rx\Observable::fromArray([\Rx\Observable::interval(100)->mapTo('a'), \Rx\Observable::interval(200)->mapTo('b'), \Rx\Observable::interval(300)->mapTo('c')])->switchFirst()->take(3);
$subscription = $source->subscribe($stdoutObserver, $scheduler);
$loop->run();
Exemplo n.º 6
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$subscription = Rx\Observable::fromArray([21, 42])->mapTo(1)->subscribe($stdoutObserver);
Exemplo n.º 7
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$source = Rx\Observable::fromArray([(object) ['value' => 0], (object) ['value' => 1], (object) ['value' => 2]])->pluck('value');
$subscription = $source->subscribe($stdoutObserver);