Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Small documentation and metadata tweaks, added a README.

  • Loading branch information...
commit 226a571382807680956af78ab39c8916665cecf8 1 parent 07b640c
@toddmazierski toddmazierski authored
Showing with 67 additions and 4 deletions.
  1. +54 −0 README.rdoc
  2. +1 −1  Rakefile
  3. +11 −2 lib/wait.rb
  4. +1 −1  wait.gemspec
View
54 README.rdoc
@@ -0,0 +1,54 @@
+# Executes a block until there's a result.
+#
+# Wait.for { rand(2).zero? }
+# => Rescued exception while waiting: Wait::Error: result was false
+# => Attempt 1/5 failed, delaying for 0.5s
+# => Rescued exception while waiting: Wait::Error: result was false
+# => Attempt 2/5 failed, delaying for 1.0s
+# => true
+#
+# By default, all exceptions are rescued.
+#
+# Wait.for do
+# if rand(2).zero?
+# true
+# else
+# raise Exception
+# end
+# end
+# => Rescued exception while waiting: Exception: Exception
+# => Attempt 1/5 failed, delaying for 0.5s
+# => true
+#
+# The attempt counter is passed to the block if special conditionals are
+# needed.
+#
+# Wait.for(:attempts => 3) { |attempt| puts Time.now if attempt == 3 }
+# => Rescued exception while waiting: Wait::Error: result was nil
+# => Attempt 1/3 failed, delaying for 0.5s
+# => Rescued exception while waiting: Wait::Error: result was nil
+# => Attempt 2/3 failed, delaying for 1.0s
+# => Sun Apr 29 10:03:17 -0400 2012
+# => Rescued exception while waiting: Wait::Error: result was nil
+# => Wait::Error: 3/3 attempts failed
+#
+# == Options
+#
+# [:attempts]
+# Number of times to attempt the block. Default is 5.
+# [:timeout]
+# Seconds the block is permitted to execute. Default is 15.
+# [:delay]
+# Initial (grows exponentially) number of seconds to wait in between
+# attempts. Default is 0.5.
+# [:exceptions]
+# Array of exceptions to rescue. Default is +Exception+ (all exceptions).
+# [:silent]
+# If +true+, silences output. Default is +false+.
+#
+# == Returns
+#
+# The result of the block if:
+# * the result is not +nil+ or +false+
+# * the block doesn't raise an exception
+# * the block doesn't time out
View
2  Rakefile
@@ -4,5 +4,5 @@ Rake::TestTask.new do |task|
task.libs << 'test'
end
-desc "Run tests"
+desc 'Run tests'
task :default => :test
View
13 lib/wait.rb
@@ -1,6 +1,6 @@
require 'timeout'
-# Executes a block until there's a result that's not nil or false.
+# Executes a block until there's a result.
#
# Wait.for { rand(2).zero? }
# => Rescued exception while waiting: Wait::Error: result was false
@@ -34,7 +34,8 @@
# => Rescued exception while waiting: Wait::Error: result was nil
# => Wait::Error: 3/3 attempts failed
#
-# ==== Supported Options
+# == Options
+#
# [:attempts]
# Number of times to attempt the block. Default is 5.
# [:timeout]
@@ -46,6 +47,14 @@
# Array of exceptions to rescue. Default is +Exception+ (all exceptions).
# [:silent]
# If +true+, silences output. Default is +false+.
+#
+# == Returns
+#
+# The result of the block if:
+# * the result is not +nil+ or +false+
+# * the block doesn't raise an exception
+# * the block doesn't time out
+
class Wait
def self.for(options = {})
View
2  wait.gemspec
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
s.name = 'wait'
s.version = '0.0.0'
s.date = '2012-04-29'
- s.summary = "Executes a block until there's a result that's not nil or false."
+ s.summary = "Executes a block until there's a result."
s.authors = ['Todd Mazierski']
s.email = 'todd@foursquare.com'
s.files = ['lib/wait.rb']
Please sign in to comment.
Something went wrong with that request. Please try again.