Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matt-taylor/timeoutable
Extends how the base Timeout klass works. This gem adds the ability to customize the ability to send a warning signal to the working thread. This allows a potential graceful shutdown prior to violent death
https://github.com/matt-taylor/timeoutable
ruby timeout
Last synced: about 14 hours ago
JSON representation
Extends how the base Timeout klass works. This gem adds the ability to customize the ability to send a warning signal to the working thread. This allows a potential graceful shutdown prior to violent death
- Host: GitHub
- URL: https://github.com/matt-taylor/timeoutable
- Owner: matt-taylor
- License: mit
- Created: 2021-06-03T05:48:48.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-08T18:14:20.000Z (over 2 years ago)
- Last Synced: 2024-12-10T10:48:08.902Z (28 days ago)
- Topics: ruby, timeout
- Language: Ruby
- Homepage: https://github.com/matt-taylor/timeoutable
- Size: 1.19 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Timeoutable
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'timeoutable', source: 'https://github.com/matt-taylor/timeoutable'
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install timeoutable
## Usage
Take a looke at the [TestableKlass](https://github.com/matt-taylor/timeoutable/blob/main/lib/timeoutable/testable_klass.rb) for complete example.
```ruby
params = {
warn: 10, # this can be a float
timeout: 15, # this can be a float
proc: ->(thread, seconds_elapsed) { thread[BIT_NAME] = 1 }, # proc to call after ${warn} seconds -- passes the original thread and the seconds that have elapsed
message: "Error message",
}Timeoutable.timeout(**params) do
# code wrapped in a timeout
end
```### How this works
After `warn` seconds have elapsed, `Timoutable` will call the `proc`. In the example, the `proc` will set a bit in the thread. However, you can choose any method of communication to gracefully shutdown.## Development
After checking out the repo, run `make bash` to install dependencies and build a container. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/matt-taylor/timeoutable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/matt-taylor/timeoutable/blob/main/CODE_OF_CONDUCT.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Timeoutable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/matt-taylor/timeoutable/blob/main/CODE_OF_CONDUCT.md).