Class: Infrastruct::BlockingQueue

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

Instance Method Summary collapse

Constructor Details

#initializeBlockingQueue

Returns a new instance of BlockingQueue.



3
4
5
6
7
# File 'lib/infrastruct/blocking_queue.rb', line 3

def initialize
  @queue = ::Queue.new
  @mutex = Mutex.new
  @blocking = true
end

Instance Method Details

#popObject



13
14
15
16
17
# File 'lib/infrastruct/blocking_queue.rb', line 13

def pop
  @mutex.synchronize do
    @queue.pop(!@blocking)
  end
end

#push(element) ⇒ Object



9
10
11
# File 'lib/infrastruct/blocking_queue.rb', line 9

def push(element)
  @queue.push(element)
end

#unblock!Object



19
20
21
22
23
# File 'lib/infrastruct/blocking_queue.rb', line 19

def unblock!
  @mutex.synchronize do
    @blocking = false
  end
end