/** * {@inheritDoc} */ public function read() { $reader = new Awaitable(); $this->readersQueue->enqueue($reader); if ($this->buffer) { while (!$this->buffer->isReadable()) { (yield $reader->await()); } $this->readersQueue->dequeue(); $this->notifyAwaiting($this->writersQueue); return $this->buffer->read()->content(); } while ($this->messageQueue->count() <= $this->indexOf($reader, $this->readersQueue)) { (yield $reader->await()); } $index = $this->indexOf($reader, $this->readersQueue); $msg = $this->messageQueue->offsetGet($index); $this->readersQueue->offsetUnset($index); $this->messageQueue->offsetUnset($index); $this->notifyAwaiting($this->readersQueue); $this->notifyAwaiting($this->writersQueue); return $msg->content(); }