/** @test */ public function itShouldReceiveForwardedEvents() { $readable = new ReadableStream(); $writable = new WritableStream(); $composite = new CompositeStream($readable, $writable); $composite->on(Event::DATA, $this->expectCallableOnce()); $composite->on(Event::DRAIN, $this->expectCallableOnce()); $readable->emit(Event::DATA, array('foo')); $writable->emit(Event::DRAIN); }
/** @test */ public function itShouldReceiveForwardedEvents() { $readable = new ReadableStream(); $writable = new WritableStream(); $composite = new CompositeStream($readable, $writable); $composite->on('data', $this->expectCallableOnce()); $composite->on('drain', $this->expectCallableOnce()); $readable->emit('data', array('foo')); $writable->emit('drain'); }
/** * launch the given interactive $command shell * * Its STDOUT will be used to parse responses, the STDIN will be used * to pass commands. * * If the command prints output to STDERR, make sure to redirect it to * STDOUT by appending " 2>&1". * * @param string|Process $process accepts either a command string to execute or a Process instance * @return DeferredShell */ public function createDeferredShell($process) { if (!$process instanceof Process) { $process = new Process($process); } $process->start($this->loop); $stream = new CompositeStream($process->stdout, $process->stdin); // forcefully terminate process when stream closes $stream->on('close', function () use($process) { if ($process->isRunning()) { $process->terminate(SIGKILL); } }); return new DeferredShell($stream); }