Module: MVLC::Thread
Instance Method Summary collapse
Instance Method Details
#new(options = {}, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mvlc/thread.rb', line 7 def new( = {}, &block) thread = ::Thread.new do begin if [:timeout] === false yield else duration = [:timeout] || 1 Timeout::timeout(duration) { yield } end rescue Timeout::Error ::Thread.current.kill rescue Exception => exception ::Thread.main.raise(exception) end end thread.abort_on_exception = true thread end |