Simple Timeout
A simple implementation of Timeout.
The standard Timeout::timeout
will always wait until the block finishes execution, and then, when the thread where the block is being executed can't be killed for some reason, your whole program get blocked. SimpleTimeout::timeout
lets you choose if you want to wait for the block to finish execution or not. By default it won't wait.
Usage
Basic usage:
SimpleTimeout::Timeout(5) do
# Some code that should not take more than 5 seconds
end
Options
SimpleTimeout::timeout
receives 4 parameters:
def self.timeout(seconds,timeout_error_class=SimpleTimeout::Error,wait_for_block=false,&block)
# the implementation ...
end
-
seconds: How much seconds to wait before raise
timeout_error_class
. - timeout_error_class: The error to raise in case of timeout.
-
wait_for_block: This one is the main reason for me to implement this gem. The standard
Timeout::timeout
will always wait until the block finishes execution, and then, when the thread where the block is been executed can't be killed for some reason, your whole program get blocked.SimpleTimeout::timeout
lets you choose if you want to wait for the block to finish execution or not. By default it won't wait. - block: The block to execute.
Installation
Add this line to your application’s Gemfile:
gem 'simple_timeout'
And then execute:
bundle
History
View the changelog
Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features