src/MemoryStream.php
protected function send(string $data, float $timeout = 0, bool $end = false): \Generator
    {
        if (!$this->isWritable()) {
            throw new UnwritableException('The stream is no longer writable.');
        }

        $this->buffer->push($data);

        if (null !== $this->delayed && !$this->buffer->isEmpty()) {
            $delayed = $this->delayed;
            $this->delayed = null;
            $delayed->resolve($this->remove());
        }

        if ($end) {
            if ($this->buffer->isEmpty()) {
                $this->free();
            } else {
                $this->writable = false;
            }
        }

        if (0 !== $this->hwm && $this->buffer->getLength() > $this->hwm) {
            $awaitable = new Delayed($this->onCancelled = $this->onCancelled ?: function () {
                $this->free();
            });
            $this->queue->push($awaitable);

            if ($timeout) {
                $awaitable = $awaitable->timeout($timeout);
            }

            yield $awaitable;
        }

        return strlen($data);
    }
protected function send(string $data, float $timeout = 0, bool $end = false): \Generator
    {
        if (!$this->isWritable()) {
            throw new UnwritableException('The stream is no longer writable.');
        }

        $this->buffer->push($data);

        if (null !== $this->delayed && !$this->buffer->isEmpty()) {
            $delayed = $this->delayed;
            $this->delayed = null;
            $delayed->resolve($this->remove());
        }

        if ($end) {
            if ($this->buffer->isEmpty()) {
                $this->free();
            } else {
                $this->writable = false;
            }
        }

        if (0 !== $this->hwm && $this->buffer->getLength() > $this->hwm) {
            $awaitable = new Delayed($this->onCancelled = $this->onCancelled ?: function () {
                $this->free();
            });
            $this->queue->push($awaitable);

            if ($timeout) {
                $awaitable = $awaitable->timeout($timeout);
            }

            yield $awaitable;
        }

        return strlen($data);
    }
@coroutine

@param string $data
@param float|int $timeout
@param bool $end

@return \Generator

@resolve int Number of bytes written to the stream.

@throws \Icicle\Stream\Exception\UnwritableException If the stream is no longer writable.