Class: Waiting

Inherits:
Object
  • Object
show all
Defined in:
lib/waiting.rb,
lib/waiting/waiter.rb,
lib/waiting/version.rb,
lib/waiting/timed_out_error.rb

Overview

Waits for things so you don’t have to

Defined Under Namespace

Classes: TimedOutError, Waiter

Constant Summary collapse

VERSION =

The version of Waiting

'1.0.0'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exp_base: self.class.default_exp_base, interval: self.class.default_interval, max_attempts: self.class.default_max_attempts, max_interval: self.class.default_max_interval) {|waiter| ... } ⇒ Waiting

Returns a new instance of Waiting.

Parameters:

  • interval (Numeric) (defaults to: self.class.default_interval)

    Polling interval in seconds.

  • max_attempts (Numeric) (defaults to: self.class.default_max_attempts)

    Number of attempts before timing out.

  • exp_base (Numeric) (defaults to: self.class.default_exp_base)

    Increases the interval by the power of attempts.

  • max_interval (Numeric) (defaults to: self.class.default_max_interval)

    Interval limit for exponential backoff.

Yields:

  • Block to check if the wait is over.

Yield Parameters:



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/waiting.rb', line 14

def initialize(exp_base: self.class.default_exp_base,
               interval: self.class.default_interval,
               max_attempts: self.class.default_max_attempts,
               max_interval: self.class.default_max_interval,
               &block)

  @exp_base = exp_base
  @interval = interval
  @max_attempts = max_attempts
  @max_interval = max_interval

  @block = block
end

Class Attribute Details

.default_exp_baseNumeric

The default exp base

Returns:

  • (Numeric)


33
34
35
# File 'lib/waiting.rb', line 33

def default_exp_base
  @default_exp_base
end

.default_intervalNumeric

The default interval

Returns:

  • (Numeric)


39
40
41
# File 'lib/waiting.rb', line 39

def default_interval
  @default_interval
end

.default_max_attemptsNumeric

The default max attempts

Returns:

  • (Numeric)


45
46
47
# File 'lib/waiting.rb', line 45

def default_max_attempts
  @default_max_attempts
end

.default_max_intervalNumeric

The default max interval

Returns:

  • (Numeric)


51
52
53
# File 'lib/waiting.rb', line 51

def default_max_interval
  @default_max_interval
end

Class Method Details

.wait(exp_base: default_exp_base, interval: default_interval, max_attempts: default_max_attempts, max_interval: default_max_interval) {|waiter| ... } ⇒ Object

Parameters:

  • interval (Numeric) (defaults to: default_interval)

    Polling interval in seconds.

  • max_attempts (Numeric) (defaults to: default_max_attempts)

    Number of attempts before timing out.

  • exp_base (Numeric) (defaults to: default_exp_base)

    Increases the interval by the power of attempts.

  • max_interval (Numeric) (defaults to: default_max_interval)

    Interval limit for exponential backoff.

Yields:

  • Block to check if the wait is over.

Yield Parameters:

See Also:

  • ++#wait+


91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/waiting.rb', line 91

def self.wait(exp_base: default_exp_base,
              interval: default_interval,
              max_attempts: default_max_attempts,
              max_interval: default_max_interval,
              &block)

  new(exp_base: exp_base,
      interval: interval,
      max_attempts: max_attempts,
      max_interval: max_interval,
      &block).wait
end

Instance Method Details

#wait(exp_base: @exp_base, interval: @interval, max_attempts: @max_attempts, max_interval: @max_interval) {|waiter| ... } ⇒ Object

Parameters:

  • interval (Numeric) (defaults to: @interval)

    Polling interval in seconds.

  • max_attempts (Numeric) (defaults to: @max_attempts)

    Number of attempts before timing out.

  • exp_base (Numeric) (defaults to: @exp_base)

    Increases the interval by the power of attempts.

  • max_interval (Numeric) (defaults to: @max_interval)

    Interval limit for exponential backoff.

Yields:

  • Block to check if the wait is over.

Yield Parameters:



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/waiting.rb', line 67

def wait(exp_base: @exp_base,
         interval: @interval,
         max_attempts: @max_attempts,
         max_interval: @max_interval,
         &block)

  Waiter.new(
    exp_base: exp_base,
    interval: interval,
    max_attempts: max_attempts,
    max_interval: max_interval
  ).wait(&(block || @block))
end