Exemplo n.º 1
0
 protected function doReduce($reduced, callable $reduce, Channel $input, bool $withCount = false) : \Generator
 {
     $n = 0;
     while ($this->eof !== ($val = (yield $input->receive($this->eof)))) {
         $reduced = $reduce($reduced, $val, $n++);
     }
     return $withCount ? [$reduced, $n] : $reduced;
 }
Exemplo n.º 2
0
 /**
  * Read the next inbound HTTP request.
  */
 public function nextRequest() : Awaitable
 {
     return $this->incoming->receive();
 }
Exemplo n.º 3
0
 protected function socketWriter($socket, Channel $channel, callable $transform = null) : \Generator
 {
     $writer = new SocketWriter($socket);
     $len = 0;
     try {
         while (null !== ($chunk = (yield $channel->receive()))) {
             $len += (yield $writer->write($transform ? $transform($chunk) : $chunk));
         }
         return $len;
     } catch (\Throwable $e) {
         $channel->close($e);
         throw $e;
     } finally {
         $writer->dispose();
     }
 }
Exemplo n.º 4
0
 /**
  * Await and consume the next message received by the WebSocket.
  * 
  * Text messages are received as strings, binaray messages are instances ReadableStream.
  * 
  * @return string|ReadableStream
  */
 public function receive() : Awaitable
 {
     return $this->messages->receive();
 }