當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Observable::mergeAll方法代碼示例

本文整理匯總了PHP中Rx\Observable::mergeAll方法的典型用法代碼示例。如果您正苦於以下問題:PHP Observable::mergeAll方法的具體用法?PHP Observable::mergeAll怎麽用?PHP Observable::mergeAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Rx\Observable的用法示例。


在下文中一共展示了Observable::mergeAll方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: it_passes_on_completed_from_sources

 /**
  * @test
  */
 public function it_passes_on_completed_from_sources()
 {
     $ys = $this->createHotObservable(array(onCompleted(250)));
     $results = $this->scheduler->startWithCreate(function () use($ys) {
         return Observable::mergeAll($ys);
     });
     $this->assertMessages(array(onCompleted(250)), $results->getMessages());
     $this->assertSubscriptions(array(subscribe(200, 250)), $ys->getSubscriptions());
 }
開發者ID:voryx,項目名稱:Rx.PHP,代碼行數:12,代碼來源:MergeAllTest.php

示例2: send

 /**
  * Squirt the metrics over UDP
  *
  * @param array $data Incoming Data
  * @param float|1 $sampleRate the rate (0-1) for sampling.
  * @param array|string $tags Key Value array of Tag => Value, or single tag as string
  *
  * @return Observable
  **/
 public function send($data, $sampleRate = 1, array $tags = null)
 {
     // sampling
     $sampledData = array();
     if ($sampleRate < 1) {
         foreach ($data as $stat => $value) {
             if (mt_rand() / mt_getrandmax() <= $sampleRate) {
                 $sampledData[] = [$stat, "{$value}|@{$sampleRate}"];
             }
         }
     } else {
         foreach ($data as $stat => $value) {
             $sampledData[] = [$stat, $value];
         }
     }
     if (empty($sampledData)) {
         return Observable::emptyObservable();
     }
     $observableSequence = Observable::fromArray($sampledData)->map(function ($d) use($tags) {
         $stat = $d[0];
         $value = $d[1];
         if ($tags !== null && is_array($tags) && count($tags) > 0) {
             $value .= '|';
             foreach ($tags as $tag_key => $tag_val) {
                 if (is_array($tag_val)) {
                     $flattenTagVal = array();
                     array_walk_recursive($array, function ($a) use(&$return) {
                         $flattenTagVal[] = $a;
                     });
                     $tag_val = implode("\n", $flattenTagVal);
                 }
                 $value .= '#' . $tag_key . ':' . $tag_val . ',';
             }
             $value = substr($value, 0, -1);
         } elseif (isset($tags) && !empty($tags)) {
             $value .= '|#' . $tags;
         }
         return $this->reportMetric("{$stat}:{$value}");
     });
     return Observable::mergeAll($observableSequence);
 }
開發者ID:domraider,項目名稱:rxnet,代碼行數:50,代碼來源:Statsd.php

示例3:

<?php

require_once __DIR__ . '/../bootstrap.php';
$loop = React\EventLoop\Factory::create();
$scheduler = new Rx\Scheduler\EventLoopScheduler($loop);
$sources = Rx\Observable::range(0, 3)->map(function ($x) {
    return Rx\Observable::range($x, 3);
});
$merged = \Rx\Observable::mergeAll($sources);
$disposable = $merged->subscribe($stdoutObserver, $scheduler);
$loop->run();
開發者ID:ReactiveX,項目名稱:RxPHP,代碼行數:11,代碼來源:merge-all.php

示例4: StdOutObserver

<?php

use EventLoop\EventLoop;
use Rx\Observable;
use Rx\Scheduler\EventLoopScheduler;
use Rxnet\Observer\StdOutObserver;
require __DIR__ . "/../../vendor/autoload.php";
$loop = EventLoop::getLoop();
/*
 * If you have no statsd server, you can run the following command to listen for UDP traffic on port 8125 :
 * $> socat - udp4-listen:8125,reuseaddr,fork
 */
$statsd = new \Rxnet\Statsd\Statsd("localhost", 8125);
$req1 = $statsd->gauge("database.connections", 42);
$req2 = $statsd->increment("database.query.count");
$req3 = $statsd->histogram("database.query.time", 0.42);
Observable::mergeAll(Observable::fromArray([$req1, $req2, $req3]))->subscribe(new StdOutObserver(), new EventLoopScheduler($loop));
$loop->run();
開發者ID:domraider,項目名稱:rxnet,代碼行數:18,代碼來源:demo.php


注:本文中的Rx\Observable::mergeAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。