Kraken\Stream\AsyncStream::handleWrite PHP Method

handleWrite() public method

Handle the outcoming stream.
public handleWrite ( )
    public function handleWrite()
    {
        $text = $this->buffer->peek();
        $sent = fwrite($this->resource, $text);
        if ($sent === false) {
            $this->emit('error', [$this, new WriteException('Error occurred while writing to the stream resource.')]);
            return;
        }
        $lenBefore = strlen($text);
        $lenAfter = $lenBefore - $sent;
        $this->buffer->remove($sent);
        if ($lenAfter > 0 && $lenBefore >= $this->bufferSize && $lenAfter < $this->bufferSize) {
            $this->emit('drain', [$this]);
        } else {
            if ($lenAfter === 0) {
                $this->loop->removeWriteStream($this->resource);
                $this->listening = false;
                $this->emit('drain', [$this]);
            }
        }
    }