Module: TimeoutInterrupt
- Defined in:
- lib/timeout_interrupt.rb
Overview
Can be included, or used directly. In both cases, it provides #timeout.
Defined Under Namespace
Classes: Error
Class Method Summary collapse
-
.timeout(seconds = nil, exception = nil, &block) ⇒ Object
Creates a timeout and calls your block, which has to finish before timeout occurs.
Instance Method Summary collapse
-
#timeout(seconds = nil, exception = nil, &block) ⇒ Object
Creates a timeout and calls your block, which has to finish before timeout occurs.
Class Method Details
.timeout(seconds = nil, exception = nil, &block) ⇒ Object
Creates a timeout and calls your block, which has to finish before timeout occurs.
You can rescue Timeout::Error, instead TimeoutInterrupt::Error, it will work too.
It will call your given block, which has seconds seconds to end.
If you want to prepare a timeout, which should be used many times,
without giving seconds and exception, you can omit the block,
so, TimeoutInterruptSingleton#timeout will return a Proc, which want to have the block.
There is a problem with scoped timeouts. If you rescue a timeout in an other timeout,
it's possible, that the other timeout will never timeout, because both are timed out at once.
Than you need to call TimeoutInterruptSingleton#timeout without arguments.
It will prepare the next timeout or it will raise it directy, if timed out.
157 158 159 |
# File 'lib/timeout_interrupt.rb', line 157 def self.timeout seconds = nil, exception = nil, &block TimeoutInterruptSingleton.timeout seconds, exception, &block end |
Instance Method Details
#timeout(seconds = nil, exception = nil, &block) ⇒ Object
This method is useful, if you include TimeoutInterrupt. You can call it directly.
Creates a timeout and calls your block, which has to finish before timeout occurs.
You can rescue Timeout::Error, instead TimeoutInterrupt::Error, it will work too.
It will call your given block, which has seconds seconds to end.
If you want to prepare a timeout, which should be used many times,
without giving seconds and exception, you can omit the block,
so, TimeoutInterruptSingleton#timeout will return a Proc, which want to have the block.
There is a problem with scoped timeouts. If you rescue a timeout in an other timeout,
it's possible, that the other timeout will never timeout, because both are timed out at once.
Than you need to call TimeoutInterruptSingleton#timeout without arguments.
It will prepare the next timeout or it will raise it directy, if timed out.
192 193 194 |
# File 'lib/timeout_interrupt.rb', line 192 def timeout seconds = nil, exception = nil, &block TimeoutInterruptSingleton.timeout seconds, exception, &block end |