本文整理汇总了PHP中Rx\Observable::emptyObservable方法的典型用法代码示例。如果您正苦于以下问题:PHP Observable::emptyObservable方法的具体用法?PHP Observable::emptyObservable怎么用?PHP Observable::emptyObservable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rx\Observable
的用法示例。
在下文中一共展示了Observable::emptyObservable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: timestamp_empty
/**
* @test
*/
public function timestamp_empty()
{
$results = $this->scheduler->startWithCreate(function () {
return Observable::emptyObservable($this->scheduler)->timestamp($this->scheduler);
});
$this->assertMessages([onCompleted(201)], $results->getMessages());
}
示例2: repeatWhen_Observable_complete
/**
* @test
*/
public function repeatWhen_Observable_complete()
{
$xs = $this->createColdObservable([onNext(10, 1), onNext(20, 2), onCompleted(30)]);
$results = $this->scheduler->startWithCreate(function () use($xs) {
return $xs->repeatWhen(function () {
return Observable::emptyObservable();
});
});
$this->assertMessages([onNext(210, 1), onNext(220, 2), onCompleted(230)], $results->getMessages());
$this->assertSubscriptions([subscribe(200, 230)], $xs->getSubscriptions());
}
示例3: __invoke
/**
* @param \Rx\ObservableInterface $observable
* @param \Rx\ObserverInterface $observer
* @param \Rx\SchedulerInterface $scheduler
* @return \Rx\DisposableInterface
*/
public function __invoke(ObservableInterface $observable, ObserverInterface $observer, SchedulerInterface $scheduler = null)
{
$buffer = "";
return $observable->defaultIfEmpty(Observable::just(null))->concat(Observable::just($this->delimiter))->concatMap(function ($x) use(&$buffer) {
if ($x === null || $buffer === null) {
$buffer = null;
return Observable::emptyObservable();
}
$items = explode($this->delimiter, $buffer . $x);
$buffer = array_pop($items);
return Observable::fromArray($items);
})->subscribe($observer, $scheduler);
}
示例4:
<?php
require_once __DIR__ . '/../bootstrap.php';
$source1 = \Rx\Observable::just(42);
$source2 = \Rx\Observable::just(56);
$source = \Rx\Observable::emptyObservable()->concat($source1)->concat($source2);
$subscription = $source->subscribe($stdoutObserver);
示例5:
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::emptyObservable()->defaultIfEmpty(new \Rx\Observable\ReturnObservable("something"));
$subscription = $source->subscribe($stdoutObserver);
示例6:
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::emptyObservable()->doOnCompleted(function () {
echo 'Do Completed', PHP_EOL;
});
$subscription = $source->subscribe($stdoutObserver);
示例7: 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);
}
示例8:
<?php
require_once __DIR__ . '/../bootstrap.php';
$observable = \Rx\Observable::emptyObservable();
$observable->subscribe($stdoutObserver);