Class: Protocol::HTTP::Body::Completable
- Defined in:
- lib/protocol/http/body/completable.rb
Overview
Invokes a callback once the body has completed, either successfully or due to an error.
Instance Attribute Summary
Attributes inherited from Wrapper
Class Method Summary collapse
Instance Method Summary collapse
- #close(error = nil) ⇒ Object
- #finish ⇒ Object
-
#initialize(body, callback) ⇒ Completable
constructor
A new instance of Completable.
Methods inherited from Wrapper
#call, #empty?, #inspect, #length, #read, #ready?, #stream?
Methods inherited from Readable
#call, #each, #empty?, #join, #length, #read, #ready?, #stream?
Constructor Details
#initialize(body, callback) ⇒ Completable
Returns a new instance of Completable.
21 22 23 24 25 |
# File 'lib/protocol/http/body/completable.rb', line 21 def initialize(body, callback) super(body) @callback = callback end |
Class Method Details
.wrap(message, &block) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/protocol/http/body/completable.rb', line 13 def self.wrap(, &block) if body = &.body and !body.empty? .body = self.new(.body, block) else yield end end |
Instance Method Details
#close(error = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/protocol/http/body/completable.rb', line 39 def close(error = nil) if @body super @callback.call(error) @body = nil end end |
#finish ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/protocol/http/body/completable.rb', line 27 def finish if @body result = super @callback.call @body = nil return result end end |