|
|
|
@ -34,7 +34,7 @@ module TimeoutInterruptSingleton |
|
|
|
|
# @return [nil] |
|
|
|
|
def raise_if_sb_timed_out |
|
|
|
|
return if self.timeouts.empty? |
|
|
|
|
key, (at, bt, exception) = self.timeouts.min_by {|key,(at,bt,ex)| at } |
|
|
|
|
_key, (at, bt, exception) = self.timeouts.min_by {|_key,(at,_bt,_ex)| at } |
|
|
|
|
return if Time.now < at |
|
|
|
|
raise exception, 'execution expired', bt |
|
|
|
|
end |
|
|
|
@ -49,7 +49,7 @@ module TimeoutInterruptSingleton |
|
|
|
|
else |
|
|
|
|
raise_if_sb_timed_out |
|
|
|
|
Signal.trap 'ALRM', &method( :alarm_trap) |
|
|
|
|
key, (at, bt) = timeouts.min_by {|key,(at,bt)| at } |
|
|
|
|
_key, (at, _bt) = timeouts.min_by {|_key,(at,_bt)| at } |
|
|
|
|
FFI::LibC.alarm (at - Time.now).to_i + 1 |
|
|
|
|
end |
|
|
|
|
nil |
|
|
|
@ -59,9 +59,9 @@ module TimeoutInterruptSingleton |
|
|
|
|
# |
|
|
|
|
# @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 seconds [nil] If this and no block given, it will call {setup} for checking and |
|
|
|
|
# preparing _next_ known timeout. |
|
|
|
|
# @param exception [exception] which exception 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, |
|
|
|
@ -70,7 +70,8 @@ module TimeoutInterruptSingleton |
|
|
|
|
# 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. |
|
|
|
|
# You can rescue `Timeout::Error`, instead `TimeoutInterrupt::Error`, |
|
|
|
|
# it is a subclass of `Timeout::Error`. |
|
|
|
|
# |
|
|
|
|
# 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, |
|
|
|
|