Class: Vx::Common::OutputBuffer
- Inherits:
-
Object
- Object
- Vx::Common::OutputBuffer
- Defined in:
- lib/vx/common/output_buffer.rb
Defined Under Namespace
Classes: ClosedBuffer
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
Instance Method Summary collapse
- #<<(str) ⇒ Object
- #close ⇒ Object
- #empty? ⇒ Boolean
- #flush ⇒ Object
-
#initialize(interval = 1, &block) ⇒ OutputBuffer
constructor
A new instance of OutputBuffer.
Constructor Details
#initialize(interval = 1, &block) ⇒ OutputBuffer
Returns a new instance of OutputBuffer.
9 10 11 12 13 14 15 16 17 |
# File 'lib/vx/common/output_buffer.rb', line 9 def initialize(interval = 1, &block) @interval = interval.to_f @buffer = "" @write = block @mutex = Mutex.new @closed = false start_watching end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
7 8 9 |
# File 'lib/vx/common/output_buffer.rb', line 7 def interval @interval end |
Instance Method Details
#<<(str) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/vx/common/output_buffer.rb', line 19 def << (str) closed! @mutex.synchronize do @buffer << str end end |
#close ⇒ Object
27 28 29 30 |
# File 'lib/vx/common/output_buffer.rb', line 27 def close @closed = true @thread.join end |
#empty? ⇒ Boolean
37 38 39 |
# File 'lib/vx/common/output_buffer.rb', line 37 def empty? @buffer.size == 0 end |
#flush ⇒ Object
32 33 34 35 |
# File 'lib/vx/common/output_buffer.rb', line 32 def flush closed! @mutex.synchronize { write } end |