Class: Chan::Counter
- Inherits:
-
Object
- Object
- Chan::Counter
- Defined in:
- lib/xchan/counter.rb
Overview
Chan::Counter provides a counter for the number of written and received bytes on a given channel.
Instance Method Summary collapse
-
#initialize(tmpdir) ⇒ Chan::Counter
constructor
-
#bytes_written ⇒ Integer
Returns the number of bytes written to a channel.
-
#bytes_read ⇒ Integer
Returns the number of bytes read from a channel.
Constructor Details
#initialize(tmpdir) ⇒ Chan::Counter
14 15 16 17 |
# File 'lib/xchan/counter.rb', line 14 def initialize(tmpdir) @io = Chan.temporary_file(%w[counter .json], tmpdir:) write(@io, {"bytes_read" => 0, "bytes_written" => 0}) end |
Instance Method Details
#bytes_written ⇒ Integer
Returns the number of bytes written to a channel
22 23 24 |
# File 'lib/xchan/counter.rb', line 22 def bytes_written read(@io).fetch("bytes_written") end |
#bytes_read ⇒ Integer
Returns the number of bytes read from a channel
29 30 31 |
# File 'lib/xchan/counter.rb', line 29 def bytes_read read(@io).fetch("bytes_read") end |