Пример #1
0
 /**
  * @param ObserverInterface $observer
  * @param SchedulerInterface|null $scheduler
  * @return \Rx\Disposable\CompositeDisposable|\Rx\DisposableInterface
  */
 public function subscribe(ObserverInterface $observer, SchedulerInterface $scheduler = null)
 {
     try {
         $stream = new StreamSubject(fopen($this->fileName, $this->mode), $this->loop);
         return $stream->subscribe($observer, $scheduler);
     } catch (\Exception $e) {
         $observer->onError($e);
         return new CallbackDisposable(function () use(&$stream) {
             if ($stream instanceof Stream) {
                 $stream->close();
             }
         });
     }
 }
Пример #2
0
 /**
  * ToFileObserver constructor.
  *
  * @param string $fileName
  * @param LoopInterface|null $loop
  */
 public function __construct($fileName, LoopInterface $loop = null)
 {
     $loop = $loop ?: \EventLoop\getLoop();
     parent::__construct(fopen($fileName, 'w'), $loop);
 }