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; }
/** * Read the next inbound HTTP request. */ public function nextRequest() : Awaitable { return $this->incoming->receive(); }
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(); } }
/** * 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(); }