Module: MVLC::Thread

Extended by:
Thread
Included in:
Thread
Defined in:
lib/mvlc/thread.rb

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(options = {}, &block)
  thread = ::Thread.new do
    begin
      if options[:timeout] === false
        yield
      else
        duration = options[: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