public function pipe(WritableStreamInterface $dest, array $options = []) { if ($this === $dest) { throw new \Exception('Can\'t pipe stream into itself!'); } Util::pipe($this, $dest, $options); return $dest; }
/** @test */ public function forwardEventsShouldSetupForwards() { $source = new ReadableStream(); $target = new ReadableStream(); Util::forwardEvents($source, $target, array(Event::DATA)); $target->on(Event::DATA, $this->expectCallableOnce()); $target->on('foo', $this->expectCallableNever()); $source->emit(Event::DATA, array('hello')); $source->emit('foo', array('bar')); }
/** * @param Process $process * @param LoopInterface $loop * @param array $options * @param float $interval * @return \React\Promise\PromiseInterface */ public static function parent(Process $process, LoopInterface $loop, array $options = [], $interval = self::INTERVAL) { $process->start($loop, $interval); return \WyriHaximus\React\tickingPromise($loop, $interval, [$process, 'isRunning'])->then(function () use($process, $options) { $messenger = new Messenger($process->stdin, $process->stdout, $process->stderr, ['read_err' => 'stderr', 'read' => 'stdout', 'write' => 'stdin', 'callForward' => function ($name, $arguments) use($process) { return call_user_func_array([$process, $name], $arguments); }] + $options); Util::forwardEvents($process, $messenger, ['exit']); return \React\Promise\resolve($messenger); }); }
protected function spawnProcess() { $processOptions = isset($this->options['processOptions']) ? $this->options['processOptions'] : []; $process = clone $this->sourceProcess; Factory::parent($process, $this->loop, $processOptions)->then(function (Messenger $messenger) { Util::forwardEvents($messenger, $this, ['error']); $this->pool->attach($messenger); $this->readyPool->enqueue($messenger); $this->emit('messenger', [$messenger, $this]); }, function ($error) { $this->emit('error', [$error, $this]); }); }
/** * Adapter constructor. * @param LoopInterface $loop * @param array $options */ public function __construct(LoopInterface $loop, array $options = [], FlysystemInterface $flysystem = null) { $this->loop = $loop; $this->invoker = \React\Filesystem\getInvoker($this, $options, 'invoker', 'React\\Filesystem\\InstantInvoker'); $this->openFileLimiter = new OpenFileLimiter(\React\Filesystem\getOpenFileLimit($options)); Flexible::createFromClass(Worker::class, $loop, ['min_size' => 0, 'max_size' => 50])->then(function (PoolInterface $pool) { $this->pool = $pool; }); Util::forwardEvents($this->pool, $this, ['error']); $this->pool->on('worker', function (WorkerInterface $worker) { $worker->rpc(Factory::rpc('setFlysystem', ['flysystem' => serialize($this->flysystem)])); }); $this->options = array_merge_recursive($this->options, $options); $this->flysystem = $flysystem; }
public function pipe(WritableStreamInterface $dest, array $options = array()) { Util::pipe($this, $dest, $options); return $dest; }
public function handlePipeEvent($source) { Util::forwardEvents($source, $this, array('error')); }
public function pipe(WritableStreamInterface $dest, array $options = []) { Util::pipe($this, $dest, $options); }
public function handlePipeEvent($source) { Util::forwardEvents($source, $this, array(Event::ERROR)); }