Skip to content

Instantly share code, notes, and snippets.

@micahalles
Created February 24, 2011 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micahalles/842276 to your computer and use it in GitHub Desktop.
Save micahalles/842276 to your computer and use it in GitHub Desktop.
fire poll
module FirePoll
# @param [String] msg a custom message raised when polling fails
# @param [Numeric] seconds number of seconds to poll
# @yield a block that determines whether polling should continue
# @yieldreturn false if polling should continue
# @yieldreturn true if polling is complete
# @raise [RuntimeError] when polling fails
# @return [void]
# @since 1.0.0
def poll(msg=nil, seconds=2.0)
(seconds * 10).to_i.times do
return if yield
sleep 0.1
end
msg ||= "polling failed after #{seconds} seconds"
raise msg
end
module_function :poll
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment