Class: Async::HTTP::Protocol::HTTP1::Finishable
- Inherits:
-
Protocol::HTTP::Body::Wrapper
- Object
- Protocol::HTTP::Body::Wrapper
- Async::HTTP::Protocol::HTTP1::Finishable
- Defined in:
- lib/async/http/protocol/http1/finishable.rb
Overview
Keeps track of whether a body is being read, and if so, waits for it to be closed.
Instance Method Summary collapse
-
#close(error = nil) ⇒ Object
Close the body and signal any waiting tasks.
-
#initialize(body) ⇒ Finishable
constructor
Initialize the finishable wrapper.
- #inspect ⇒ Object
-
#read ⇒ Object
Read the next chunk from the body.
- #reading? ⇒ Boolean
-
#wait(persistent = true) ⇒ Object
Wait for the body to be fully consumed or discard it.
Constructor Details
#initialize(body) ⇒ Finishable
Initialize the finishable wrapper.
18 19 20 21 22 23 24 25 |
# File 'lib/async/http/protocol/http1/finishable.rb', line 18 def initialize(body) super(body) @closed = Async::Promise.new @error = nil @reading = false end |
Instance Method Details
#close(error = nil) ⇒ Object
Close the body and signal any waiting tasks.
41 42 43 44 45 46 47 48 |
# File 'lib/async/http/protocol/http1/finishable.rb', line 41 def close(error = nil) super unless @closed.resolved? @error = error @closed.resolve(true) end end |
#inspect ⇒ Object
65 66 67 |
# File 'lib/async/http/protocol/http1/finishable.rb', line 65 def inspect "#<#{self.class} closed=#{@closed} error=#{@error}> | #{super}" end |
#read ⇒ Object
Read the next chunk from the body.
34 35 36 37 38 |
# File 'lib/async/http/protocol/http1/finishable.rb', line 34 def read @reading = true super end |
#reading? ⇒ Boolean
28 29 30 |
# File 'lib/async/http/protocol/http1/finishable.rb', line 28 def reading? @reading end |
#wait(persistent = true) ⇒ Object
Wait for the body to be fully consumed or discard it.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/async/http/protocol/http1/finishable.rb', line 52 def wait(persistent = true) if @reading @closed.wait elsif persistent # If the connection can be reused, let's gracefully discard the body: self.discard else # Else, we don't care about the body, so we can close it immediately: self.close end end |