SoftTimeout
SoftTimeout provides feature to set soft expiry time before raising actual Timeout Exception.
Installation
Add this line to your application's Gemfile:
gem 'soft_timeout'
And then execute:
$ bundle
Or install it yourself as:
$ gem install soft_timeout
Usage
class MyClass
def initialize
@continue_running = true
end
def some_important_task
timeout = SoftTimeout::Timeout.new(10, 20) do
@continue_running = false
end
timeout.soft_timeout do
100.times do |n|
if @continue_running
...
some heavy processing (sleep(2))
...
else
puts 'soft timeout reached'
return
end
end
end
end
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/abhi-patel/soft_timeout. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.