Module: Timeout
- Defined in:
- lib/polyphony/extensions/timeout.rb
Overview
Timeout extensions
Class Method Summary collapse
-
.timeout(sec, klass = Timeout::Error, message = 'execution expired', &block) ⇒ any
Sets a timeout for the given block.
Class Method Details
.timeout(sec, klass = Timeout::Error, message = 'execution expired', &block) ⇒ any
Sets a timeout for the given block. This method provides an equivalent API to the stock Timeout API provided by Ruby. In case of a timeout, the block will be interrupted and an exception will be raised according to the given arguments.
16 17 18 19 20 21 22 |
# File 'lib/polyphony/extensions/timeout.rb', line 16 def self.timeout(sec, klass = Timeout::Error, = 'execution expired', &block) if sec.nil? || sec == 0 block.call else cancel_after(sec, with_exception: [klass, ], &block) end end |