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



15
16
17
18
# File 'lib/xchan/counter.rb', line 15

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



23
24
25
# File 'lib/xchan/counter.rb', line 23

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



30
31
32
# File 'lib/xchan/counter.rb', line 30

def bytes_read
  read(@io).fetch("bytes_read")
end