1
0
mirror of https://github.com/danog/process.git synced 2024-11-30 04:39:04 +01:00

Create Message objects on construct

Immediately buffers STDOUT and STDERR.
This commit is contained in:
Aaron Piotrowski 2017-01-15 09:46:41 -06:00
parent 7ccef896ee
commit aedbcbe339

View File

@ -17,6 +17,12 @@ class StreamedProcess {
/** @var \Amp\Emitter Emits bytes read from STDERR. */ /** @var \Amp\Emitter Emits bytes read from STDERR. */
private $stderrEmitter; private $stderrEmitter;
/** @var \Amp\Message */
private $stdoutMessage;
/** @var \Amp\Message */
private $stderrMessage;
/** @var string|null */ /** @var string|null */
private $stdinWatcher; private $stdinWatcher;
@ -40,6 +46,8 @@ class StreamedProcess {
$this->process = new Process($command, $cwd, $env, $options); $this->process = new Process($command, $cwd, $env, $options);
$this->stdoutEmitter = new Emitter; $this->stdoutEmitter = new Emitter;
$this->stderrEmitter = new Emitter; $this->stderrEmitter = new Emitter;
$this->stdoutMessage = new Message($this->stdoutEmitter->stream());
$this->stderrMessage = new Message($this->stderrEmitter->stream());
$this->writeQueue = new \SplQueue; $this->writeQueue = new \SplQueue;
} }
@ -53,6 +61,8 @@ class StreamedProcess {
$this->stderrWatcher = null; $this->stderrWatcher = null;
$this->stdoutEmitter = new Emitter; $this->stdoutEmitter = new Emitter;
$this->stderrEmitter = new Emitter; $this->stderrEmitter = new Emitter;
$this->stdoutMessage = new Message($this->stdoutEmitter->stream());
$this->stderrMessage = new Message($this->stderrEmitter->stream());
$this->writeQueue = new \SplQueue; $this->writeQueue = new \SplQueue;
} }
@ -193,21 +203,21 @@ class StreamedProcess {
} }
/** /**
* Each call returns a new Message object. * Message buffering the output of STDOUT.
* *
* @return \Amp\Message * @return \Amp\Message
*/ */
public function getStdout(): Message { public function getStdout(): Message {
return new Message($this->stdoutEmitter->stream()); return $this->stdoutMessage;
} }
/** /**
* Each call returns a new Message object. * Message buffering the output of STDERR.
* *
* @return \Amp\Message * @return \Amp\Message
*/ */
public function getStderr(): Message { public function getStderr(): Message {
return new Message($this->stderrEmitter->stream()); return $this->stderrMessage;
} }
/** /**