Class: 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.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #first_chunk_duration ⇒ Object
-
#initialize(start_time, body, callback) ⇒ Statistics
constructor
A new instance of Statistics.
- #inspect ⇒ Object
- #read ⇒ Object
- #stop(error) ⇒ Object
- #to_s ⇒ Object
- #total_duration ⇒ Object
Methods inherited from Wrapper
Methods inherited from Readable
Constructor Details
#initialize(start_time, body, callback) ⇒ Statistics
Returns a new instance of Statistics.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/async/http/statistics.rb', line 46 def initialize(start_time, body, callback) super(body) @length = 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.
60 61 62 |
# File 'lib/async/http/statistics.rb', line 60 def end_time @end_time end |
#first_chunk_time ⇒ Object (readonly)
Returns the value of attribute first_chunk_time.
59 60 61 |
# File 'lib/async/http/statistics.rb', line 59 def first_chunk_time @first_chunk_time end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
62 63 64 |
# File 'lib/async/http/statistics.rb', line 62 def length @length end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
58 59 60 |
# File 'lib/async/http/statistics.rb', line 58 def start_time @start_time end |
Instance Method Details
#first_chunk_duration ⇒ Object
70 71 72 73 74 |
# File 'lib/async/http/statistics.rb', line 70 def first_chunk_duration if @first_chunk_time @first_chunk_time - @start_time end end |
#inspect ⇒ Object
110 111 112 |
# File 'lib/async/http/statistics.rb', line 110 def inspect "#{super} | \#<#{self.class} #{self.to_s}>" end |
#read ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/async/http/statistics.rb', line 82 def read chunk = super @first_chunk_time ||= Clock.now if chunk @length += chunk.length else complete_statistics end return chunk end |
#stop(error) ⇒ Object
76 77 78 79 80 |
# File 'lib/async/http/statistics.rb', line 76 def stop(error) complete_statistics(error) super end |
#to_s ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/async/http/statistics.rb', line 96 def to_s parts = ["sent #{@length} 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 |