Class: Waiter

Inherits:
Object
  • Object
show all
Defined in:
lib/record_store/provider/provider_utils/waiter.rb

Direct Known Subclasses

BackoffWaiter, RateLimitWaiter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil) ⇒ Waiter

Returns a new instance of Waiter.



2
3
4
# File 'lib/record_store/provider/provider_utils/waiter.rb', line 2

def initialize(message = nil)
  @message = message || 'Waiting'
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/record_store/provider/provider_utils/waiter.rb', line 6

def message
  @message
end

Instance Method Details

#wait(sleep_time, message: @message) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/record_store/provider/provider_utils/waiter.rb', line 8

def wait(sleep_time, message: @message)
  while sleep_time > 0
    wait_time = [10, sleep_time].min
    puts "#{message} (#{sleep_time}s left)" if wait_time > 1
    sleep(wait_time)
    sleep_time -= wait_time
  end
end