예제 #1
0
 /**
  * @test
  */
 public function connectable_observable_disconnect_future()
 {
     $xs = $this->createHotObservable([onNext(210, 1), onNext(220, 2), onNext(230, 3), onNext(240, 4), onCompleted(250)]);
     $subject = new TestSubject();
     $conn = new ConnectableObservable($xs, $subject);
     $subject->disposeOn(3, $conn->connect());
     $results = $this->scheduler->startWithCreate(function () use($xs, $conn) {
         return $conn;
     });
     $this->assertMessages([onNext(210, 1), onNext(220, 2), onNext(230, 3)], $results->getMessages());
 }
예제 #2
0
 /**
  * @param \Rx\ObserverInterface $observer
  * @param null $scheduler
  * @return \Rx\Disposable\CallbackDisposable
  */
 public function subscribe(ObserverInterface $observer, $scheduler = null)
 {
     $this->count++;
     $shouldConnect = $this->count === 1;
     $subscription = $this->source->subscribe($observer, $scheduler);
     if ($shouldConnect) {
         $this->connectableSubscription = $this->source->connect();
     }
     $isDisposed = false;
     return new CallbackDisposable(function () use($subscription, &$isDisposed) {
         if ($isDisposed) {
             return;
         }
         $isDisposed = true;
         $subscription->dispose();
         $this->count--;
         if ($this->count === 0) {
             $this->connectableSubscription->dispose();
         }
     });
 }