channel = new CoChannel($size); $this->queue = new SplQueue(); } public function pop(float $timeout): ConnectionInterface|false { if ($this->isCoroutine()) { return $this->channel->pop($timeout); } return $this->queue->shift(); } public function push(ConnectionInterface $data): bool { if ($this->isCoroutine()) { return $this->channel->push($data); } $this->queue->push($data); return true; } public function length(): int { if ($this->isCoroutine()) { return $this->channel->getLength(); } return $this->queue->count(); } protected function isCoroutine(): bool { return Coroutine::id() > 0; } }