Class: LogMsgQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/lpxc.rb

Instance Method Summary collapse

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

#flushObject



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

Returns:

  • (Boolean)


26
27
28
# File 'lib/lpxc.rb', line 26

def full?
  @locker.synchronize {@array.size >= @max}
end