emptyObservable() public static method

Returns an empty observable sequence.
public static emptyObservable ( ) : Rx\Observable\EmptyObservable
return Rx\Observable\EmptyObservable An observable sequence with no elements.
示例#1
0
 /**
  * @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
0
 /**
  * @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
0
 /**
  * @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
0
<?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
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::emptyObservable()->defaultIfEmpty(new \Rx\Observable\ReturnObservable("something"));
$subscription = $source->subscribe($stdoutObserver);
示例#6
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::emptyObservable()->doOnCompleted(function () {
    echo 'Do Completed', PHP_EOL;
});
$subscription = $source->subscribe($stdoutObserver);
示例#7
0
 /**
  * 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
0
<?php

require_once __DIR__ . '/../bootstrap.php';
$observable = \Rx\Observable::emptyObservable();
$observable->subscribe($stdoutObserver);