コード例 #1
0
 /**
  * @param \Rx\ObserverInterface $observer
  * @param null $scheduler
  * @return CallbackDisposable|\Rx\Disposable\EmptyDisposable|\Rx\DisposableInterface|\Rx\Subject\InnerSubscriptionDisposable
  */
 public function subscribe(ObserverInterface $observer, $scheduler = null)
 {
     if ($scheduler) {
         $this->scheduler = $scheduler;
     }
     return $this->subject->subscribe($observer, $scheduler);
 }
コード例 #2
0
 /**
  * @inheritDoc
  */
 public function __invoke(ObservableInterface $observable, ObserverInterface $observer, SchedulerInterface $scheduler = null)
 {
     $outerDisposable = new SerialDisposable();
     $this->disposable->add($outerDisposable);
     $subscribe = function () use($outerDisposable, $observable, $observer, $scheduler, &$subscribe) {
         $this->sourceComplete = false;
         $outerSubscription = $observable->subscribe(new CallbackObserver([$observer, "onNext"], [$observer, "onError"], function () use($observer, &$subscribe, $outerDisposable) {
             $this->sourceComplete = true;
             if (!$this->repeat) {
                 $observer->onCompleted();
                 return;
             }
             $outerDisposable->setDisposable(new EmptyDisposable());
             $this->completions->onNext(++$this->count);
         }), $scheduler);
         $outerDisposable->setDisposable($outerSubscription);
     };
     $notifierDisposable = $this->notifier->subscribe(new CallbackObserver(function () use(&$subscribe, $scheduler) {
         $subscribe();
     }, function ($ex) use($observer) {
         $this->repeat = false;
         $observer->onError($ex);
     }, function () use($observer) {
         $this->repeat = false;
         if ($this->sourceComplete) {
             $observer->onCompleted();
         }
     }), $scheduler);
     $this->disposable->add($notifierDisposable);
     try {
         $handled = call_user_func($this->notificationHandler, $this->completions->asObservable());
         $handledDisposable = $handled->subscribe($this->notifier, $scheduler);
         $this->disposable->add($handledDisposable);
     } catch (\Exception $e) {
         $observer->onError($e);
         return new EmptyDisposable();
     }
     $subscribe();
     return $this->disposable;
 }
コード例 #3
0
ファイル: StreamSubject.php プロジェクト: RxPHP/RxStream
 public function subscribe(ObserverInterface $observer, $scheduler = null)
 {
     $this->stream->on('data', function ($data) use($observer) {
         $observer->onNext($data);
     });
     $this->stream->on('error', function ($error) use($observer) {
         $ex = $error instanceof \Exception ? $error : new \Exception($error);
         $observer->onError($ex);
     });
     $this->stream->on('close', function () use($observer) {
         $observer->onCompleted();
     });
     $disposable = parent::subscribe($observer, $scheduler);
     return new BinaryDisposable($disposable, new CallbackDisposable(function () use($observer) {
         $this->removeObserver($observer);
         $this->dispose();
     }));
 }
コード例 #4
0
ファイル: BehaviorSubject.php プロジェクト: voryx/Rx.PHP
 public function subscribe(ObserverInterface $observer, $scheduler = null)
 {
     $disposable = parent::subscribe($observer, $scheduler);
     $observer->onNext($this->value);
     return $disposable;
 }
コード例 #5
0
ファイル: SubjectTest.php プロジェクト: ReactiveX/RxPHP
 /**
  * @test
  */
 public function it_does_not_pass_if_already_stopped()
 {
     $subject = new Subject();
     $observer = $this->createMock('Rx\\ObserverInterface');
     $observer->expects($this->once())->method('onCompleted');
     $observer->expects($this->never())->method('onNext');
     $observer->expects($this->never())->method('onError');
     $subject->subscribe($observer);
     $subject->onCompleted();
     $subject->onError(new Exception('fail'));
     $subject->onNext(42);
     $subject->onCompleted();
 }
コード例 #6
0
ファイル: Client.php プロジェクト: RxPHP/RxWebsocket
 public function subscribe(ObserverInterface $observer, $scheduler = null)
 {
     if (!$this->isStopped) {
         $this->startConnection();
     }
     return parent::subscribe($observer, $scheduler);
 }