当前位置: 首页>>代码示例>>PHP>>正文


PHP Observable::timer方法代码示例

本文整理汇总了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));
 }
开发者ID:RxPHP,项目名称:RxAwait,代码行数:13,代码来源:FunctionAwaitTest.php

示例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());
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:13,代码来源:ConcatAllTest.php

示例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);
     });
 }
开发者ID:domraider,项目名称:rxnet,代码行数:11,代码来源:RetryWithDelay.php

示例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();
     });
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:22,代码来源:TimerObservableTest.php

示例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();
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:8,代码来源:skipUntil.php

示例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();
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:27,代码来源:groupByUntil.php

示例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!
开发者ID:ihor,项目名称:RxPHP,代码行数:10,代码来源:timer.php

示例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";
开发者ID:RxPHP,项目名称:RxAwait,代码行数:10,代码来源:interval_timeout.php

示例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);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:22,代码来源:CombineLatestTest.php

示例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();
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:8,代码来源:takeUntil.php

示例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();
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:16,代码来源:shareReplay.php


注:本文中的Rx\Observable::timer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。