本文整理汇总了PHP中Rx\Observable::timer方法的典型用法代码示例。如果您正苦于以下问题:PHP Observable::timer方法的具体用法?PHP Observable::timer怎么用?PHP Observable::timer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rx\Observable
的用法示例。
在下文中一共展示了Observable::timer方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: await_default_timeout
/**
* @test
*/
public function await_default_timeout()
{
$start = microtime(true);
$observable = Observable::never()->takeUntil(Observable::timer(2000));
$generator = \Rx\await($observable);
foreach ($generator as $item) {
}
$totalTime = microtime(true) - $start;
$this->assertEquals('2', round($totalTime));
}
示例2: concatAll_timer_missing_item
/**
* @test
*/
public function concatAll_timer_missing_item()
{
$xs = $this->createHotObservable([onNext(201, 0), onNext(206, 1), onNext(211, 2), onCompleted(212)]);
$results = $this->scheduler->startWithCreate(function () use($xs) {
return $xs->map(function ($x) {
return Observable::timer(5)->mapTo($x);
})->concatAll();
});
$this->assertMessages([onNext(206, 0), onNext(211, 1), onNext(216, 2), onCompleted(216)], $results->getMessages());
}
示例3: __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);
});
}
示例4: timer_one_shot_relative_time_throws
/**
* @test
*/
public function timer_one_shot_relative_time_throws()
{
$scheduler1 = new TestScheduler();
$xs = Observable::timer(1, $scheduler1);
$xs->subscribeCallback(function () {
throw new \Exception();
});
$this->assertException(function () use($scheduler1) {
$scheduler1->start();
});
$scheduler2 = new TestScheduler();
$ys = Observable::timer(1, $scheduler2);
$ys->subscribeCallback(null, null, function () {
throw new \Exception();
});
$this->assertException(function () use($scheduler2) {
$scheduler2->start();
});
}
示例5:
<?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();
示例6: function
<?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();
示例7:
<?php
require_once __DIR__ . '/../bootstrap.php';
$loop = new \React\EventLoop\StreamSelectLoop();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$source = \Rx\Observable::timer(200, $scheduler);
$source->subscribe($createStdoutObserver());
$loop->run();
//Next value: 0
//Complete!
示例8:
<?php
require __DIR__ . '/../vendor/autoload.php';
$source = \Rx\Observable::interval(1000)->takeUntil(\Rx\Observable::timer(10000));
//timeout after 10 seconds
$generator = \Rx\await($source);
foreach ($generator as $item) {
echo $item, PHP_EOL;
}
echo "DONE";
示例9: combineLatest_delay
/**
* @test
*/
public function combineLatest_delay()
{
$loop = Factory::create();
$scheduler = new EventLoopScheduler($loop);
$source1 = Observable::timer(100);
$source2 = Observable::timer(120);
$source3 = Observable::timer(140);
$source = $source1->combineLatest([$source2, $source3]);
$result = null;
$completed = false;
$source->subscribe(new CallbackObserver(function ($x) use(&$result) {
$result = $x;
}, null, function () use(&$completed) {
$completed = true;
}), $scheduler);
$loop->run();
$this->assertEquals([0, 0, 0], $result);
$this->assertTrue($completed);
}
示例10:
<?php
require_once __DIR__ . '/../bootstrap.php';
$loop = \React\EventLoop\Factory::create();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$source = \Rx\Observable::interval(105, $scheduler)->takeUntil(\Rx\Observable::timer(1000));
$subscription = $source->subscribe($stdoutObserver, $scheduler);
$loop->run();
示例11: use
<?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();