try-eager
Try to run proc repeatedly until options[:until]
returns true. Ruby >= 2.0.0 is required.
Installation
Add this line to your application's Gemfile:
gem 'try-eager'
And then execute:
$ bundle
Or install it yourself as:
$ gem install try-eager
Usage
require 'try/eager'
# wait for mail to receive and raise TimeoutError when Mail not found in 10 seconds
mail = Try.eager until: ->(m) { m.to_addrs.any? {|a| a.include?('sunaot') } do
Mail.last
end
# wait for mail to receive with max retry 3 times (no timeout)
mail = Try.(3.times, until: ->(m) { m.body.include?('sunaot') }) do
Mail.last
end
# you may also set timeout sec and interval sec
Try.eager until: ->(args) { false },
timeout: 2,
interval: 0.5 do
puts :hello
end
Contributing
- Fork it ( http://github.com/sunaot/try-eager/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request