Class: LogMsgQueue
- Inherits:
-
Object
- Object
- LogMsgQueue
- Defined in:
- lib/lpxc.rb
Instance Method Summary collapse
- #enqueue(msg) ⇒ Object
- #flush ⇒ Object
- #full? ⇒ Boolean
-
#initialize(max) ⇒ LogMsgQueue
constructor
A new instance of LogMsgQueue.
Constructor Details
#initialize(max) ⇒ LogMsgQueue
Returns a new instance of LogMsgQueue.
8 9 10 11 12 |
# File 'lib/lpxc.rb', line 8 def initialize(max) @locker = Mutex.new @max = max @array = [] end |
Instance Method Details
#enqueue(msg) ⇒ Object
14 15 16 |
# File 'lib/lpxc.rb', line 14 def enqueue(msg) @locker.synchronize {@array << msg} end |
#flush ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/lpxc.rb', line 18 def flush @locker.synchronize do old = @array @array = [] return old end end |
#full? ⇒ Boolean
26 27 28 |
# File 'lib/lpxc.rb', line 26 def full? @locker.synchronize {@array.size >= @max} end |