當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。