Module: Uttk::Strategies::Strategy::UttkTimeout
- Defined in:
- lib/uttk/strategies/Strategy.rb
Class Method Summary collapse
Class Method Details
.timeout(sec, flow, exception = Error, &block) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/uttk/strategies/Strategy.rb', line 66 def timeout(sec, flow, exception=Error, &block) return block[] if sec == nil or sec.zero? begin x = Thread.current y = Thread.start do sleep sec if x.alive? flow << :abort x.raise exception, "execution expired" end end block[sec] ensure y.kill if y and y.alive? end end |