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

Instance Method Summary collapse

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.

Parameters:

  • seconds (0) (defaults to: nil)

    No timeout, so block can take any time.

  • seconds (Integer) (defaults to: nil)

    In ‘seconds` Seconds, it should raise a timeout, if not finished.

  • seconds (nil) (defaults to: nil)

    If also no block given, everything will be ignored and it will call setup for checking and preparing next known timeout.

  • exception (Exception) (defaults to: nil)

    which will be raised if timed out.

  • exception (nil) (defaults to: nil)

    ‘TimeoutInterrupt::Error` will be used to raise.

  • block (Proc)

    Will be called and should finish its work before it timed out.

  • block (nil)

    Nothing will happen, instead it will return a Proc, which can be called with a block to use the timeout.

Returns:

  • 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.

Raises:

  • exception

See Also:



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

Note:

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.

Parameters:

  • seconds (0) (defaults to: nil)

    No timeout, so block can take any time.

  • seconds (Integer) (defaults to: nil)

    In ‘seconds` Seconds, it should raise a timeout, if not finished.

  • seconds (nil) (defaults to: nil)

    If also no block given, everything will be ignored and it will call setup for checking and preparing next known timeout.

  • exception (Exception) (defaults to: nil)

    which will be raised if timed out.

  • exception (nil) (defaults to: nil)

    ‘TimeoutInterrupt::Error` will be used to raise.

  • block (Proc)

    Will be called and should finish its work before it timed out.

  • block (nil)

    Nothing will happen, instead it will return a Proc, which can be called with a block to use the timeout.

Returns:

  • 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.

Raises:

  • exception

See Also:



192
193
194
# File 'lib/timeout_interrupt.rb', line 192

def timeout seconds = nil, exception = nil, &block
	TimeoutInterruptSingleton.timeout seconds, exception, &block
end