本文整理汇总了PHP中Rx\Observable::range方法的典型用法代码示例。如果您正苦于以下问题:PHP Observable::range方法的具体用法?PHP Observable::range怎么用?PHP Observable::range使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rx\Observable
的用法示例。
在下文中一共展示了Observable::range方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: range_dispose
/**
* @test
*/
public function range_dispose()
{
$results = $this->scheduler->startWithDispose(function () {
return Observable::range(-10, 5, $this->scheduler);
}, 204);
$this->assertMessages([onNext(201, -10), onNext(202, -9), onNext(203, -8)], $results->getMessages());
}
示例2: __invoke
public function __invoke(Observable $attempts)
{
return Observable::range(1, $this->max)->zip([$attempts], function ($i, $e) {
if ($i >= $this->max) {
throw $e;
}
return $i;
})->flatMap(function ($i) {
return Observable::timer(1000);
});
}
示例3: list
<?php
require_once __DIR__ . '/../bootstrap.php';
list($evens, $odds) = \Rx\Observable::range(0, 10)->partition(function ($x) {
return $x % 2 === 0;
});
$evens->subscribe($createStdoutObserver('Evens '));
$odds->subscribe($createStdoutObserver('Odds '));
示例4:
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = Rx\Observable::range(0, 3)->map(function ($x) {
return \Rx\Observable::range($x, 3);
})->concatAll();
$subscription = $source->subscribe($stdoutObserver);
示例5:
<?php
require_once __DIR__ . '/../bootstrap.php';
/* With publish */
$interval = \Rx\Observable::range(0, 10);
$source = $interval->take(2)->doOnNext(function ($x) {
echo "Side effect\n";
});
$published = $source->publish();
$published->subscribe($createStdoutObserver('SourceC '));
$published->subscribe($createStdoutObserver('SourceD '));
$published->connect();
示例6:
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::range(1, 5)->takeWhile(function ($x) {
return $x < 3;
});
$subscription = $source->subscribe($stdoutObserver);
示例7:
<?php
require_once __DIR__ . '/../bootstrap.php';
$observable = \Rx\Observable::range(0, 3);
$observable->subscribe($stdoutObserver);
示例8:
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::range(0, 5)->takeLast(3);
$source->subscribe($stdoutObserver);
示例9:
<?php
require_once __DIR__ . '/../bootstrap.php';
$loop = React\EventLoop\Factory::create();
$scheduler = new Rx\Scheduler\EventLoopScheduler($loop);
$observable = Rx\Observable::range(1, 5);
$selectManyObservable = $observable->flatMapTo(\Rx\Observable::range(0, 2));
$disposable = $selectManyObservable->subscribe($stdoutObserver, $scheduler);
$loop->run();
示例10:
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::range(1, 3)->repeat(3);
$subscription = $source->subscribe($createStdoutObserver());
//Next value: 1
//Next value: 2
//Next value: 3
//Next value: 1
//Next value: 2
//Next value: 3
//Next value: 1
//Next value: 2
//Next value: 3
//Complete!
示例11:
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::range(0, 3)->doOnNext(function ($x) {
echo 'Do Next:', $x, PHP_EOL;
});
$subscription = $source->subscribe($stdoutObserver);
示例12:
<?php
require_once __DIR__ . '/../bootstrap.php';
$loop = \React\EventLoop\Factory::create();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$source = \Rx\Observable::range(1, 3)->flatMapLatest(function ($x) {
return \Rx\Observable::fromArray([$x . 'a', $x . 'b']);
});
$source->subscribe($stdoutObserver, $scheduler);
$loop->run();
示例13:
<?php
include __DIR__ . "/../../vendor/autoload.php";
$toFile = new \Rx\React\ToFileObserver(__DIR__ . "/../test2.csv");
\Rx\Observable::range(1, 20)->take(5)->mapTo("This is pretty cool \n")->subscribe($toFile);
示例14: function
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::range(0, 3)->doOnEach(new \Rx\Observer\CallbackObserver(function ($x) {
echo 'Do Next:', $x, PHP_EOL;
}, function (Exception $err) {
echo 'Do Error:', $err->getMessage(), PHP_EOL;
}, function () {
echo 'Do Completed', PHP_EOL;
}));
$subscription = $source->subscribe($stdoutObserver);
示例15: testWithImmediateSchedulerWithRecursion
public function testWithImmediateSchedulerWithRecursion()
{
$completed = false;
$emitted = null;
Observable::range(0, 10)->flatMap(function ($x) use(&$count) {
if (++$count < 2) {
return Observable::error(new \Exception("Something"));
}
return Observable::just(42);
})->retry(3)->take(1)->subscribe(new CallbackObserver(function ($x) use(&$emitted) {
$emitted = $x;
}, null, function () use(&$completed) {
$completed = true;
}), new ImmediateScheduler());
$this->assertTrue($completed);
$this->assertEquals(42, $emitted);
}