Exemplo n.º 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);
 }
Exemplo n.º 2
0
 /**
  * @test
  *
  */
 public function promise_failure()
 {
     $source = new Subject();
     $source->onError(new Exception("some error"));
     $promise = Promise::fromObservable($source);
     $promise->then(function ($value) {
         $this->assertTrue(false);
     }, function ($error) {
         $this->assertEquals($error, new Exception("some error"));
     });
 }
Exemplo n.º 3
0
 /**
  * @param int $count
  * @return void
  */
 public function produceNext($count = 1)
 {
     if ($this->completed) {
         return;
     }
     for ($i = 0; $i < $count; $i++) {
         if (!$this->isIteratorValid()) {
             $this->completed = true;
             $this->obs->onCompleted();
             return;
         }
         $this->obs->onNext($this->iterator->current());
         $this->iterator->next();
     }
 }
Exemplo n.º 4
0
 /**
  * @param $sourceDir
  * @param $targetDir
  * @param $isDryRun
  * @return Observable\ConnectableObservable
  */
 public function execute($sourceDir, $targetDir, $isDryRun)
 {
     $files = Observable::fromIterator($this->filesystem->ls($sourceDir));
     $filesWithDate = $this->fileWithDateRepository->extractDateFrom($files)->publish();
     $symlinkCommands = $this->symlinkCommandRepository->createSymlinkCommands($filesWithDate, new Path($targetDir));
     $summary = $this->summaryRepository->summarize($filesWithDate);
     $symlinkCommands->merge($summary)->subscribe($this->output);
     if (!$isDryRun) {
         $symlinkCommands->subscribeCallback(function (SymlinkCommand $cmd) {
             $this->output->onNext("write file");
             $this->linkRepository->createLink($cmd->getSource(), $cmd->getTarget());
         });
     }
     $filesWithDate->connect();
 }
Exemplo n.º 5
0
 public function dispose()
 {
     if (!$this->hasObservers()) {
         parent::dispose();
         $this->stream->end();
     }
 }
Exemplo n.º 6
0
 /**
  * @inheritDoc
  */
 public function __invoke(ObservableInterface $observable, ObserverInterface $observer, SchedulerInterface $scheduler = null)
 {
     $errors = new Subject();
     $disposable = new CompositeDisposable();
     $sourceDisposable = new EmptyDisposable();
     $innerCompleted = false;
     $sourceError = false;
     try {
         $when = call_user_func($this->notificationHandler, $errors->asObservable());
     } catch (\Exception $e) {
         $observer->onError($e);
         return;
     }
     $subscribeToSource = function () use($observer, $disposable, $observable, &$sourceError, $errors, &$sourceDisposable, $scheduler, &$innerCompleted) {
         $sourceError = false;
         $sourceDisposable = $observable->subscribe(new CallbackObserver([$observer, 'onNext'], function ($err) use(&$sourceError, $errors, $disposable, &$sourceDisposable, &$innerCompleted, $observer) {
             $sourceError = true;
             $disposable->remove($sourceDisposable);
             $sourceDisposable->dispose();
             if ($innerCompleted) {
                 $observer->onCompleted();
                 return;
             }
             $errors->onNext($err);
         }, [$observer, 'onCompleted']), $scheduler);
         $disposable->add($sourceDisposable);
     };
     $whenDisposable = $when->subscribe(new CallbackObserver(function ($x) use($subscribeToSource, &$sourceError) {
         if ($sourceError) {
             $sourceError = false;
             $subscribeToSource();
         }
     }, [$observer, 'onError'], function () use(&$innerCompleted, &$sourceError, $observer) {
         $innerCompleted = true;
         if ($sourceError) {
             $observer->onCompleted();
         }
     }), $scheduler);
     $disposable->add($whenDisposable);
     $subscribeToSource();
     return $disposable;
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
0
 public function dispose()
 {
     parent::dispose();
     unset($this->value);
 }
Exemplo n.º 9
0
 public function onCompleted()
 {
     if (!$this->isDisposed()) {
         parent::onCompleted();
         $this->dispose();
     }
 }
Exemplo n.º 10
0
 /**
  * @test
  * @expectedException RuntimeException
  */
 public function it_passes_on_next_if_disposed()
 {
     $subject = new Subject();
     $value = 42;
     $subject->dispose();
     $subject->onNext($value);
 }
Exemplo n.º 11
0
 public function onCompleted()
 {
     $this->sendFrame($this->createCloseFrame());
     // notify subscribers
     parent::onCompleted();
 }
Exemplo n.º 12
0
 public function subscribe(ObserverInterface $observer, $scheduler = null)
 {
     if (!$this->isStopped) {
         $this->startConnection();
     }
     return parent::subscribe($observer, $scheduler);
 }
Exemplo n.º 13
0
 public function onNext($event)
 {
     parent::onNext($event);
     $this->notifyCompleted();
 }
Exemplo n.º 14
0
 /**
  * Stop listening
  */
 public function shutdown()
 {
     $this->io->shutdown();
     $this->observable->notifyCompleted();
 }