Class: Rmega::Pool

Inherits:
Object
  • Object
show all
Includes:
Options
Defined in:
lib/rmega/pool.rb

Instance Method Summary collapse

Methods included from Options

included, #options

Constructor Details

#initializePool

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 = options.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_exceptionsObject



16
17
18
# File 'lib/rmega/pool.rb', line 16

def threads_raises_exceptions
  Thread.abort_on_exception = true
end

#wait_doneObject 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