Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/foursquare/wait
wait gem: executes a block until there's a result
https://github.com/foursquare/wait
Last synced: 3 months ago
JSON representation
wait gem: executes a block until there's a result
- Host: GitHub
- URL: https://github.com/foursquare/wait
- Owner: foursquare
- License: apache-2.0
- Created: 2012-04-29T14:17:32.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2020-02-29T08:02:54.000Z (almost 5 years ago)
- Last Synced: 2024-04-14T07:56:10.529Z (10 months ago)
- Language: Ruby
- Homepage: http://foursquare.github.com/wait/
- Size: 114 KB
- Stars: 9
- Watchers: 4
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](http://travis-ci.org/foursquare/wait)
## Description
The wait gem executes a block until there's a result. Useful for blocking script execution until:
* an HTTP request was successful
* a port has opened
* an external process has started
* etc.## Installation
Add to your `Gemfile`:
```ruby
gem 'wait', :git => '[email protected]:foursquare/wait.git'
```## Examples
```ruby
wait = Wait.new
# => #
wait.until { Time.now.sec.even? }
# Rescued exception while waiting: Wait::NoResultError: result was false
# Attempt 1/5 failed, delaying for 1s
# => true
```If you wish to handle an exception by attempting the block again, pass one or an array of exceptions with the `:rescue` option.
```ruby
wait = Wait.new(:rescue => RuntimeError)
# => #
wait.until do |attempt|
case attempt
when 1 then nil
when 2 then raise RuntimeError
when 3 then 'foo'
end
end
# Rescued exception while waiting: Wait::NoResultError: result was nil
# Attempt 1/5 failed, delaying for 1s
# Rescued exception while waiting: RuntimeError: RuntimeError
# Attempt 2/5 failed, delaying for 2s
# => "foo"
```## Options
- :attempts
- Number of times to attempt the block. Default is
5
. - :timeout
- Seconds until the block times out. Default is
15
. - :delay
- Initial (grows exponentially) delay (in seconds) to wait in between attempts. Default is
1
. - :rescue
- One or an array of exceptions to rescue. Default is
nil
. - :debug
- If
true
, logs debugging output. Default isfalse
.
## Documentation
RDoc-generated documentation available [here](http://foursquare.github.com/wait/).