Module: WaitFor

Defined in:
lib/waitfor/timer.rb,
lib/waitfor.rb,
lib/waitfor/version.rb,
lib/waitfor/timeout_error.rb,
lib/waitfor/settings/parser.rb,
lib/waitfor/settings/configuration.rb,
lib/waitfor/settings/legacy_parser.rb

Overview

Author:

  • James Bobowski

Defined Under Namespace

Modules: Settings, VERSION Classes: TimeoutError, Timer

Class Method Summary collapse

Class Method Details

.upto(options) { ... } ⇒ Object

Execute the given block until it returns true or the specified timeout is reached.

Examples:

WaitFor.upto( 30.seconds ) do
  has_event_happened?
end
WaitFor.upto( :minute => 1, :seconds => 30 ) do
  has_event_happened?
end

Parameters:

  • options (Hash)

    the options for upon( )

Options Hash (options):

  • :seconds (Fixnum)

    Timeout in seconds

  • :minutes (String)

    Timeout in minutes

  • :exception (String)

    Exception to throw if timeout is reached

  • :message (String)

    Custom message for exception if timeout is reached

Yields:

  • Block to execute until it returns true



33
34
35
36
37
38
# File 'lib/waitfor.rb', line 33

def upto( options )
  timer = Timer.new options
  until yield or timer.out_of_time?
    Kernel.sleep 1
  end
end