class Completable
Invokes a callback once the body has completed, either successfully or due to an error.
Definitions
def self.wrap(message, &block)
Wrap a message body with a callback. If the body is empty, the callback is invoked immediately.
Signature
-
parameter
message
Request | Response
the message body.
-
parameter
block
Proc
the callback to invoke when the body is closed.
Implementation
def self.wrap(message, &block)
if body = message&.body and !body.empty?
message.body = self.new(message.body, block)
else
yield
end
end
def initialize(body, callback)
Initialize the completable body with a callback.
Signature
-
parameter
body
Readable
the body to wrap.
-
parameter
callback
Proc
the callback to invoke when the body is closed.
Implementation
def initialize(body, callback)
super(body)
@callback = callback
end
def rewindable?
Signature
-
returns
Boolean
completable bodies are not rewindable.
Implementation
def rewindable?
false
end
def rewind
Rewind the body, is not supported.
Implementation
def rewind
false
end
def close(error = nil)
Close the body and invoke the callback. If an error is given, it is passed to the callback.
The calback is only invoked once, and before super
is invoked.
Implementation
def close(error = nil)
if @callback
@callback.call(error)
@callback = nil
end
super
end