Class: BlockingQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/wattics-api-client/blocking_queue.rb

Direct Known Subclasses

PriorityBlockingQueue

Instance Method Summary collapse

Constructor Details

#initializeBlockingQueue

Returns a new instance of BlockingQueue.



2
3
4
5
6
# File 'lib/wattics-api-client/blocking_queue.rb', line 2

def initialize
  @mutex = Mutex.new
  @queue = []
  @received = ConditionVariable.new
end

Instance Method Details

#<<(x) ⇒ Object



8
9
10
11
12
13
# File 'lib/wattics-api-client/blocking_queue.rb', line 8

def <<(x)
  @mutex.synchronize do
    @queue << x
    @received.signal
  end
end

#is_empty?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/wattics-api-client/blocking_queue.rb', line 22

def is_empty?
  @queue.empty?
end

#popObject



15
16
17
18
19
20
# File 'lib/wattics-api-client/blocking_queue.rb', line 15

def pop
  @mutex.synchronize do
    @received.wait(@mutex) while is_empty?
    @queue.shift
  end
end