module TimeoutInterrupt
Can be included, or used directly. In both cases, it provides {#timeout}.
Public Class Methods
Creates a timeout and calls your block, which has to finish before timeout occurs.
@param seconds [0] No timeout, so block can take any time. @param seconds [Integer] In `seconds` Seconds, it should raise a timeout, if not finished. @param seconds [nil] If also no block given, everything will be ignored and
it will call {setup} for checking and preparing next known timeout.
@param exception [Exception] which will be raised if timed out. @param exception [nil] `TimeoutInterrupt::Error` will be used to raise. @param block [Proc] Will be called and should finish its work before it timed out. @param block [nil] Nothing will happen, instead it will return a Proc,
which can be called with a block to use the timeout.
@return If block given, the returned value of your block.
Or if not, it will return a Proc, which will expect a Proc if called. This Proc has no arguments and will prepare a timeout, like if you had given a block.
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.
@see TimeoutInterrupt#timeout
@see TimeoutInterruptSingleton.timeout
@raise exception
# File lib/timeout_interrupt.rb, line 173 def self.timeout seconds = nil, exception = nil, &block TimeoutInterruptSingleton.timeout seconds, exception, &block end
Public Instance Methods
Creates a timeout and calls your block, which has to finish before timeout occurs.
@param seconds [0] No timeout, so block can take any time. @param seconds [Integer] In `seconds` Seconds, it should raise a timeout, if not finished. @param seconds [nil] If also no block given, everything will be ignored and
it will call {setup} for checking and preparing next known timeout.
@param exception [Exception] which will be raised if timed out. @param exception [nil] `TimeoutInterrupt::Error` will be used to raise. @param block [Proc] Will be called and should finish its work before it timed out. @param block [nil] Nothing will happen, instead it will return a Proc,
which can be called with a block to use the timeout.
@return If block given, the returned value of your block.
Or if not, it will return a Proc, which will expect a Proc if called. This Proc has no arguments and will prepare a timeout, like if you had given a block.
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.
@note This method is useful, if you `include TimeoutInterrupt`. You can call it directly. @see TimeoutInterrupt.timeout
@see TimeoutInterruptSingleton.timeout
@raise exception
# File lib/timeout_interrupt.rb, line 208 def timeout seconds = nil, exception = nil, &block TimeoutInterruptSingleton.timeout seconds, exception, &block end