public function bufferReadAsync(int $length): \Generator
    {
        if ($this->read_check_after && $length + $this->read_check_pos >= $this->read_check_after) {
            if ($length + $this->read_check_pos > $this->read_check_after) {
                throw new \danog\MadelineProto\Exception('Tried to read too much out of frame data');
            }
            $data = yield $this->read_buffer->bufferRead($length);
            hash_update($this->read_hash, $data);
            $hash = $this->getReadHash();
            if ($hash !== yield $this->read_buffer->bufferRead(strlen($hash))) {
                throw new \danog\MadelineProto\Exception('Hash mismatch');
            }

            return $data;
        }
        $data = yield $this->read_buffer->bufferRead($length);
        hash_update($this->read_hash, $data);
        if ($this->read_check_after) {
            $this->read_check_pos += $length;
        }

        return $data;
    }