Class: Rmega::Pool

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

Constant Summary collapse

MAX =
4

Instance Method Summary collapse

Constructor Details

#initialize(max = MAX) ⇒ Pool

Returns a new instance of Pool.



7
8
9
10
11
12
13
14
15
16
# File 'lib/rmega/pool.rb', line 7

def initialize(max = MAX)
  Thread.abort_on_exception = true

  @mutex = Mutex.new
  @resource = ConditionVariable.new
  @max = max || MAX

  @running = []
  @queue = []
end

Instance Method Details

#defer(&block) ⇒ Object



18
19
20
21
# File 'lib/rmega/pool.rb', line 18

def defer(&block)
  synchronize { @queue << block }
  process_queue
end

#wait_doneObject



23
24
25
# File 'lib/rmega/pool.rb', line 23

def wait_done
  synchronize { @resource.wait(@mutex) }
end