Class: PromisePool::Queue

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

Instance Method Summary collapse

Constructor Details

#initializeQueue

Returns a new instance of Queue.


6
7
8
9
# File 'lib/promise_pool/queue.rb', line 6

def initialize
  @queue = []
  @condv = ConditionVariable.new
end

Instance Method Details

#<<(task) ⇒ Object


15
16
17
18
# File 'lib/promise_pool/queue.rb', line 15

def << task
  queue << task
  condv.signal
end

#clearObject


29
30
31
# File 'lib/promise_pool/queue.rb', line 29

def clear
  queue.clear
end

#pop(mutex, timeout = 60) ⇒ Object


20
21
22
23
24
25
26
27
# File 'lib/promise_pool/queue.rb', line 20

def pop mutex, timeout=60
  if queue.empty?
    condv.wait(mutex, timeout)
    queue.shift || lambda{ |_| false } # shutdown idle workers
  else
    queue.shift
  end
end

#sizeObject


11
12
13
# File 'lib/promise_pool/queue.rb', line 11

def size
  @queue.size
end