本文整理汇总了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());
}
示例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);
}
示例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();
示例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();