Class: RestCore::ThreadPool::Queue
- Inherits:
-
Object
- Object
- RestCore::ThreadPool::Queue
- Defined in:
- lib/rest-core/thread_pool.rb
Instance Method Summary collapse
- #<<(task) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #pop(mutex, timeout = 60) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
12 13 14 15 |
# File 'lib/rest-core/thread_pool.rb', line 12 def initialize @queue = [] @condv = ConditionVariable.new end |
Instance Method Details
#<<(task) ⇒ Object
21 22 23 24 |
# File 'lib/rest-core/thread_pool.rb', line 21 def << task queue << task condv.signal end |
#clear ⇒ Object
35 36 37 |
# File 'lib/rest-core/thread_pool.rb', line 35 def clear queue.clear end |
#pop(mutex, timeout = 60) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/rest-core/thread_pool.rb', line 26 def pop mutex, timeout=60 if queue.empty? condv.wait(mutex, timeout) queue.shift || lambda{ |_| false } # shutdown idle workers else queue.shift end end |
#size ⇒ Object
17 18 19 |
# File 'lib/rest-core/thread_pool.rb', line 17 def size @queue.size end |