Module: MrDarcy::Drivers::Thread

Defined in:
lib/mr_darcy/drivers/thread.rb

Class Method Summary collapse

Class Method Details

.dispatch(&block) ⇒ Object

Create a new thread with the supplied block and store it on the thread stack.



12
13
14
15
# File 'lib/mr_darcy/drivers/thread.rb', line 12

def dispatch(&block)
  @threads ||= []
  @threads << ::Thread.new(&block)
end

.waitObject

Iterate through all threads in the thread stack and wait until they are complete.



19
20
21
22
23
24
25
# File 'lib/mr_darcy/drivers/thread.rb', line 19

def wait
  @threads ||= []
  @threads.each do |thread|
    thread.join unless ::Thread.current == thread
  end
  yield
end