class Protocol::HTTP::Body::Completable

Invokes a callback once the body has completed, either successfully or due to an error.

def self.wrap(message, &block)

@parameter block [Proc] the callback to invoke when the body is closed.
@parameter message [Request | Response] the message body.

Wrap a message body with a callback. If the body is empty, the callback is invoked immediately.
def self.wrap(message, &block)
	if body = message&.body and !body.empty?
		message.body = self.new(message.body, block)
	else
		yield
	end
end

def close(error = nil)

The calback is only invoked once, and before `super` is invoked.

Close the body and invoke the callback. If an error is given, it is passed to the callback.
def close(error = nil)
	if @callback
		@callback.call(error)
		@callback = nil
	end
	
	super
end

def initialize(body, callback)

@parameter callback [Proc] the callback to invoke when the body is closed.
@parameter body [Readable] the body to wrap.

Initialize the completable body with a callback.
def initialize(body, callback)
	super(body)
	
	@callback = callback
end

def rewind

Rewind the body, is not supported.
def rewind
	false
end

def rewindable?

@returns [Boolean] completable bodies are not rewindable.
def rewindable?
	false
end