Class: Chan::Counter

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(tmpdir) ⇒ Chan::Counter

Parameters:

  • tmpdir (String)

    Directory where temporary files are stored



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_writtenInteger

Returns the number of bytes written to a channel

Returns:

  • (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_readInteger

Returns the number of bytes read from a channel

Returns:

  • (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