示例#1
0
 /**
  * {@inheritDoc}
  */
 public function close() : self
 {
     $this->pipeSource = null;
     $this->readable->close();
     $this->writable->close();
     return $this;
 }
示例#2
0
 /**
  * @param ReadableStreamInterface $source
  * @param WritableStreamInterface $destination
  * @param array                   $options
  *
  * @return WritableStreamInterface
  */
 public function pipeAll(ReadableStreamInterface $source, WritableStreamInterface $destination, array $options = [])
 {
     // TODO: use stream_copy_to_stream
     // it is 4x faster than this
     // but can lose data under load with no way to recover it
     $destination->emit('pipe', array($source));
     $source->on('data', function ($data) use($source, $destination) {
         $feedMore = $destination->write($data);
         if (false === $feedMore) {
             $source->pause();
         }
     });
     $destination->on('drain', function () use($source) {
         $source->resume();
     });
     $end = isset($options['end']) ? $options['end'] : true;
     if ($end && $source !== $destination) {
         $source->on('end', function () use($destination) {
             $destination->end();
         });
     }
     return $destination;
 }
示例#3
0
 public static function createPromise(ReadableStreamInterface $stream) : PromiseInterface
 {
     $sink = new static();
     $stream->pipe($sink);
     return $sink->promise();
 }