Class: Async::HTTP::Body::Statistics
- Inherits:
-
Protocol::HTTP::Body::Wrapper
- Object
- Protocol::HTTP::Body::Wrapper
- Async::HTTP::Body::Statistics
- Defined in:
- lib/async/http/statistics.rb
Overview
Invokes a callback once the body has finished reading.
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#first_chunk_time ⇒ Object
readonly
Returns the value of attribute first_chunk_time.
-
#sent ⇒ Object
readonly
Returns the value of attribute sent.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
-
#close(error = nil) ⇒ Object
Close the body and record the end time.
- #first_chunk_duration ⇒ Object
-
#initialize(start_time, body, callback) ⇒ Statistics
constructor
Initialize the statistics body wrapper.
- #inspect ⇒ Object
-
#read ⇒ Object
Read the next chunk from the body, tracking timing and bytes sent.
- #to_s ⇒ Object
- #total_duration ⇒ Object
Constructor Details
#initialize(start_time, body, callback) ⇒ Statistics
Initialize the statistics body wrapper.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/async/http/statistics.rb', line 45 def initialize(start_time, body, callback) super(body) @sent = 0 @start_time = start_time @first_chunk_time = nil @end_time = nil @callback = callback end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
59 60 61 |
# File 'lib/async/http/statistics.rb', line 59 def end_time @end_time end |
#first_chunk_time ⇒ Object (readonly)
Returns the value of attribute first_chunk_time.
58 59 60 |
# File 'lib/async/http/statistics.rb', line 58 def first_chunk_time @first_chunk_time end |
#sent ⇒ Object (readonly)
Returns the value of attribute sent.
61 62 63 |
# File 'lib/async/http/statistics.rb', line 61 def sent @sent end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
57 58 59 |
# File 'lib/async/http/statistics.rb', line 57 def start_time @start_time end |
Instance Method Details
#close(error = nil) ⇒ Object
Close the body and record the end time.
78 79 80 81 82 |
# File 'lib/async/http/statistics.rb', line 78 def close(error = nil) complete_statistics(error) super end |
#first_chunk_duration ⇒ Object
71 72 73 74 75 |
# File 'lib/async/http/statistics.rb', line 71 def first_chunk_duration if @first_chunk_time @first_chunk_time - @start_time end end |
#inspect ⇒ Object
114 115 116 |
# File 'lib/async/http/statistics.rb', line 114 def inspect "#{super} | \#<#{self.class} #{self.to_s}>" end |
#read ⇒ Object
Read the next chunk from the body, tracking timing and bytes sent.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/async/http/statistics.rb', line 86 def read chunk = super @first_chunk_time ||= Clock.now if chunk @sent += chunk.bytesize end return chunk end |
#to_s ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/async/http/statistics.rb', line 99 def to_s parts = ["sent #{@sent} bytes"] if duration = self.total_duration parts << "took #{format_duration(duration)} in total" end if duration = self.first_chunk_duration parts << "took #{format_duration(duration)} until first chunk" end return parts.join("; ") end |
#total_duration ⇒ Object
64 65 66 67 68 |
# File 'lib/async/http/statistics.rb', line 64 def total_duration if @end_time @end_time - @start_time end end |