Method: Tpool#run

Defined in:
lib/tpool.rb

#run(*args, &blk) ⇒ Object

Runs the given block in the thread-pool, joins it and returns the result.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tpool.rb', line 63

def run(*args, &blk)
  raise "No block was given." if !blk
  
  block = Tpool::Block.new(
    :args => args,
    :blk => blk,
    :tpool => self,
    :thread_starts => [Thread.current]
  )
  @queue << block
  
  begin
    Thread.stop
  rescue Exception
    #Its not possible to stop main thread (dead-lock-error - sleep it instead).
    sleep 0.1 while !block.done?
  end
  
  return block.res
end