GithubHelp home page GithubHelp logo

isabella232 / wait-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from foursquare/wait

0.0 0.0 0.0 117 KB

wait gem: executes a block until there's a result

Home Page: http://foursquare.github.com/wait/

License: Apache License 2.0

Shell 11.86% Ruby 88.14%

wait-1's Introduction

Build Status

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:

gem 'wait', :git => '[email protected]:foursquare/wait.git'

Examples

wait = Wait.new
# => #<Wait>
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.

wait = Wait.new(:rescue => RuntimeError)
# => #<Wait>
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 is false.

Documentation

RDoc-generated documentation available here.

wait-1's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.