Skip to content

Commit

Permalink
Add optional loop to FromFileObservable
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwdan committed Feb 29, 2016
1 parent cecd45b commit fb267e0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/FromFileObservable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Rx\React;

use React\EventLoop\LoopInterface;
use React\Stream\Stream;
use Rx\Disposable\CallbackDisposable;
use Rx\Extra\Operator\CutOperator;
Expand All @@ -17,11 +18,15 @@ class FromFileObservable extends Observable
/** @var string */
private $mode;

/** @var LoopInterface */
private $loop;

public function __construct($fileName, $mode = "r")
public function __construct($fileName, $mode = "r", LoopInterface $loop = null)
{
$this->fileName = $fileName;
$this->mode = $mode;
$this->loop = $loop ?: \EventLoop\getLoop();

}

/**
Expand All @@ -33,7 +38,7 @@ public function subscribe(ObserverInterface $observer, SchedulerInterface $sched
{

try {
$stream = new Stream(fopen($this->fileName, $this->mode), \EventLoop\getLoop());
$stream = new Stream(fopen($this->fileName, $this->mode), $this->loop);

$stream->on('data', function ($data) use ($observer) {
$observer->onNext($data);
Expand Down

0 comments on commit fb267e0

Please sign in to comment.