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


PHP Observable::interval方法代码示例

本文整理汇总了PHP中Rx\Observable::interval方法的典型用法代码示例。如果您正苦于以下问题:PHP Observable::interval方法的具体用法?PHP Observable::interval怎么用?PHP Observable::interval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rx\Observable的用法示例。


在下文中一共展示了Observable::interval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAsObservablePassThroughScheduler

 public function testAsObservablePassThroughScheduler()
 {
     $loop = Factory::create();
     $scheduler = new EventLoopScheduler($loop);
     $gotValue = false;
     Observable::interval(10)->asObservable()->take(1)->subscribe(new CallbackObserver(function ($x) use(&$gotValue) {
         $this->assertEquals(0, $x);
         $gotValue = true;
     }), $scheduler);
     $loop->run();
     $this->assertTrue($gotValue);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:12,代码来源:AsObservableTest.php

示例2: testDisposeInsideFirstSchedulePeriodicAction

 public function testDisposeInsideFirstSchedulePeriodicAction()
 {
     $loop = Factory::create();
     $scheduler = new EventLoopScheduler($loop);
     $completed = false;
     $nextCount = 0;
     Observable::interval(50, $scheduler)->take(1)->subscribe(new CallbackObserver(function ($x) use(&$nextCount) {
         $nextCount++;
     }, function ($err) {
         throw $err;
     }, function () use(&$completed) {
         $completed = true;
     }));
     $loop->run();
     $this->assertTrue($completed);
     $this->assertEquals(1, $nextCount);
 }
开发者ID:voryx,项目名称:Rx.PHP,代码行数:17,代码来源:EventLoopSchedulerTest.php

示例3: use

<?php

use EventLoop\EventLoop;
use Ramsey\Uuid\UuidInterface;
use Rxnet\Observer\StdOutObserver;
use Rxnet\RabbitMq\RabbitMessage;
require __DIR__ . "/../../vendor/autoload.php";
$loop = EventLoop::getLoop();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$rabbit = new \Rxnet\RabbitMq\RabbitMq('rabbit://guest:guest@127.0.0.1:5672/', new \Rxnet\Serializer\Serialize());
// Open connection (lazy way)
$channel = \Rxnet\awaitOnce($rabbit->connect());
$exchange = $rabbit->exchange('amq.direct', [], $channel);
// Every .2s
\Rx\Observable::interval(200)->take(10000)->map(function () {
    return \Ramsey\Uuid\Uuid::uuid4();
})->flatMap(function (UuidInterface $id) use($exchange) {
    return $exchange->produce($id, '/routing/key')->map(function () use($id) {
        return "{$id}\n";
    });
})->subscribe(new StdOutObserver(), $scheduler);
// Open a new channel (lazy way)
$channel = \Rxnet\awaitOnce($rabbit->channel());
$queue = $rabbit->queue('test_queue', [], $channel);
// Say we want to prefetch 1 message at a time
$queue->setQos(1);
// Start one consumer
$queue->consume("Consumer-1")->subscribeCallback(function (RabbitMessage $message) use($scheduler) {
    echo "- consumer 1 consumed : {$message->getData()}\n";
    // Wait 1s to ack
    $scheduler->schedule([$message, 'ack'], 1000);
开发者ID:domraider,项目名称:rxnet,代码行数:31,代码来源:all-in-one.php

示例4:

<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = \React\EventLoop\Factory::create();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$obs = \Rx\Observable::interval(100, $scheduler)->take(3)->mapWithIndex(function ($i) {
    return $i;
});
$source = Rx\Observable::range(0, 5)->concatMapTo($obs);
$subscription = $source->subscribe($stdoutObserver);
$loop->run();
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:11,代码来源:concatMapTo.php

示例5:

<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = new \React\EventLoop\StreamSelectLoop();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
\Rx\Observable::interval(1000, $scheduler)->doOnNext(function ($x) {
    echo "Side effect: " . $x . "\n";
})->delay(1000)->take(5)->subscribe($createStdoutObserver(), $scheduler);
$loop->run();
开发者ID:voryx,项目名称:Rx.PHP,代码行数:9,代码来源:delay.php

示例6: use

<?php

use EventLoop\EventLoop;
use Rxnet\Operator\RetryWithDelay;
require __DIR__ . "/../../vendor/autoload.php";
$loop = EventLoop::getLoop();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$http = new \Rxnet\Http\Http();
// Or multi
$words = ['reactiveX', 'php', 'yolo'];
\Rx\Observable::interval(100)->takeWhile(function () use(&$words) {
    return $words;
})->map(function () use(&$words) {
    return array_shift($words);
})->subscribeCallback(function ($word) use($http, $scheduler) {
    echo "Query for {$word}\n";
    $http->get("https://www.google.com/search?q={$word}")->timeout(1000)->retry(3)->subscribeCallback(function () use($word) {
        echo "Get search response for {$word} \n";
    }, function (\Exception $e) use($word) {
        echo "Get and error for {$word} : {$e->getMessage()} \n";
    }, null, $scheduler);
}, null, null, $scheduler);
开发者ID:domraider,项目名称:rxnet,代码行数:22,代码来源:complex.php

示例7:

<?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

示例8: use

<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = \React\EventLoop\Factory::create();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$source = Rx\Observable::range(0, 5)->concatMap(function ($x, $i) use($scheduler) {
    return \Rx\Observable::interval(100, $scheduler)->take($x)->map(function () use($i) {
        return $i;
    });
});
$subscription = $source->subscribe($stdoutObserver);
$loop->run();
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:12,代码来源:concatMap.php

示例9:

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

示例10:

<?php

require __DIR__ . '/../vendor/autoload.php';
$source = \Rx\Observable::interval(1000);
$generator = \Rx\await($source);
foreach ($generator as $item) {
    echo $item, PHP_EOL;
}
echo "DONE";
开发者ID:RxPHP,项目名称:RxAwait,代码行数:9,代码来源:interval.php

示例11:

<?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(2)->doOnNext(function ($x) {
    echo $x, " something", PHP_EOL;
    echo "Side effect", PHP_EOL;
});
$published = $source->replay(function (\Rx\Observable $x) {
    return $x->take(2)->repeat(2);
}, 3);
$published->subscribe($createStdoutObserver('SourceA '), $scheduler);
$published->subscribe($createStdoutObserver('SourceB '), $scheduler);
$loop->run();
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:16,代码来源:replay.php

示例12:

<?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

示例13:

<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = new \React\EventLoop\StreamSelectLoop();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$source = \Rx\Observable::interval(1000, $scheduler)->timestamp()->map(function (\Rx\Timestamped $x) {
    return $x->getValue() . ':' . $x->getTimestampMillis();
})->take(5);
$source->subscribe($createStdoutObserver());
$loop->run();
// Next value: 0:1460781738354
// Next value: 1:1460781739358
// Next value: 2:1460781740359
// Next value: 3:1460781741362
// Next value: 4:1460781742367
// Complete!
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:16,代码来源:timestamp.php

示例14: concatMap_UseFunction

 /**
  * @test
  */
 public function concatMap_UseFunction()
 {
     $xs = $this->createHotObservable([onNext(210, 4), onNext(220, 3), onNext(250, 5), onNext(270, 1), onCompleted(290)]);
     $results = $this->scheduler->startWithCreate(function () use($xs) {
         return $xs->concatMap(function ($x) {
             return Observable::interval(10, $this->scheduler)->map(function () use($x) {
                 return $x;
             })->take($x);
         });
     });
     $this->assertMessages([onNext(220, 4), onNext(230, 4), onNext(240, 4), onNext(250, 4), onNext(260, 3), onNext(270, 3), onNext(280, 3), onNext(290, 5), onNext(300, 5), onNext(310, 5), onNext(320, 5), onNext(330, 5), onNext(340, 1), onCompleted(340)], $results->getMessages());
     $this->assertSubscriptions([subscribe(200, 290)], $xs->getSubscriptions());
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:16,代码来源:ConcatMapTest.php

示例15:

<?php

require __DIR__ . '/../vendor/autoload.php';
$source = \Rx\Observable::interval(1000)->take(5);
//Take the first 5
$generator = \Rx\await($source);
foreach ($generator as $item) {
    echo $item, PHP_EOL;
}
echo "DONE";
开发者ID:RxPHP,项目名称:RxAwait,代码行数:10,代码来源:interval_take.php


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