public function discard(Context $context): Promise
    {
        return $context->task(function (Context $context) {
            $len = 0;
            
            try {
                while (null !== ($chunk = yield $this->read($context, 0xFFFF))) {
                    $len += \strlen($chunk);
                }
            } catch (StreamClosedException $e) {
                // Ignore this case as we are discarding all data anyways.
            } finally {
                $this->close();
            }
            
            return $len;
        });
    }