Class: Rmega::Pool
Instance Method Summary collapse
- #defer(&block) ⇒ Object (also: #process)
-
#initialize ⇒ Pool
constructor
A new instance of Pool.
- #threads_raises_exceptions ⇒ Object
- #wait_done ⇒ Object (also: #shutdown)
Methods included from Options
Constructor Details
#initialize ⇒ Pool
Returns a new instance of Pool.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rmega/pool.rb', line 5 def initialize threads_raises_exceptions @mutex = Mutex.new @resource = ConditionVariable.new @max = .thread_pool_size @running = [] @queue = [] end |
Instance Method Details
#defer(&block) ⇒ Object Also known as: process
20 21 22 23 |
# File 'lib/rmega/pool.rb', line 20 def defer(&block) synchronize { @queue << block } process_queue end |
#threads_raises_exceptions ⇒ Object
16 17 18 |
# File 'lib/rmega/pool.rb', line 16 def threads_raises_exceptions Thread.abort_on_exception = true end |
#wait_done ⇒ Object Also known as: shutdown
27 28 29 30 |
# File 'lib/rmega/pool.rb', line 27 def wait_done return if done? synchronize { @resource.wait(@mutex) } end |