Class: Nonnative::Timeout
- Inherits:
-
Object
- Object
- Nonnative::Timeout
- Defined in:
- lib/nonnative/timeout.rb
Overview
Small helper to run a block with a timeout and convert timeout errors into false.
This is used internally for readiness/shutdown loops (for example port checks) where the common control-flow is “keep retrying until the timeout elapses”.
Instance Method Summary collapse
-
#initialize(time) ⇒ Timeout
constructor
A new instance of Timeout.
-
#perform { ... } ⇒ Object, false
Executes the given block with the configured timeout.
Constructor Details
#initialize(time) ⇒ Timeout
Returns a new instance of Timeout.
19 20 21 |
# File 'lib/nonnative/timeout.rb', line 19 def initialize(time) @time = time end |
Instance Method Details
#perform { ... } ⇒ Object, false
Executes the given block with the configured timeout.
If the timeout elapses, returns false instead of raising Timeout::Error.
29 30 31 32 33 |
# File 'lib/nonnative/timeout.rb', line 29 def perform(&) ::Timeout.timeout(time, &) rescue ::Timeout::Error false end |