Module: LightIO::Library::Timeout
Constant Summary collapse
- Error =
::Timeout::Error
Instance Method Summary collapse
Instance Method Details
#timeout(sec, klass = Error, &blk) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/lightio/library/timeout.rb', line 7 def timeout(sec, klass=Error, &blk) return yield(sec) if sec.nil? or sec.zero? beam = LightIO::Beam.new(sec, &blk) = "execution expired" if beam.join(sec).nil? raise klass, else beam.value end end |