class Protocol::HTTP::Body::Completable

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

Public Class Methods

new(body, callback) click to toggle source
Calls superclass method
# File lib/protocol/http/body/completable.rb, line 38
def initialize(body, callback)
        super(body)
        
        @callback = callback
end
wrap(message) { || ... } click to toggle source
# File lib/protocol/http/body/completable.rb, line 30
def self.wrap(message, &block)
        if body = message&.body and !body.empty?
                message.body = self.new(message.body, block)
        else
                yield
        end
end

Public Instance Methods

close(error = nil) click to toggle source
Calls superclass method
# File lib/protocol/http/body/completable.rb, line 56
def close(error = nil)
        if @body
                super
                
                @callback.call(error)
                
                @body = nil
        end
end
finish() click to toggle source
Calls superclass method
# File lib/protocol/http/body/completable.rb, line 44
def finish
        if @body
                result = super
                
                @callback.call
                
                @body = nil
                
                return result
        end
end