Class: Aws::Waiters::Waiter Private
- Inherits:
-
Object
- Object
- Aws::Waiters::Waiter
- Defined in:
- lib/aws-sdk-core/waiters/waiter.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- RAISE_HANDLER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Seahorse::Client::Plugins::RaiseResponseErrors::Handler
Instance Attribute Summary collapse
- #delay ⇒ Float (also: #interval) private
- #max_attempts ⇒ Integer private
- #poller ⇒ Object readonly private
Instance Method Summary collapse
-
#before_attempt {|attempts| ... } ⇒ Object
private
Register a callback that is invoked before every polling attempt.
-
#before_wait {|attempts, response| ... } ⇒ Object
private
Register a callback that is invoked after an attempt but before sleeping.
-
#initialize(options = {}) ⇒ Waiter
constructor
private
A new instance of Waiter.
- #wait(options) ⇒ Object private
Constructor Details
#initialize(options = {}) ⇒ Waiter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Waiter.
12 13 14 15 16 17 18 |
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 12 def initialize( = {}) @poller = [:poller] @max_attempts = [:max_attempts] @delay = [:delay] @before_attempt = Array([:before_attempt]) @before_wait = Array([:before_wait]) end |
Instance Attribute Details
#delay ⇒ Float Also known as: interval
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 |
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 27 def delay @delay end |
#max_attempts ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 |
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 24 def max_attempts @max_attempts end |
#poller ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 |
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 21 def poller @poller end |
Instance Method Details
#before_attempt {|attempts| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Register a callback that is invoked before every polling attempt. Yields the number of attempts made so far.
waiter.before_attempt do |attempts|
puts "#{attempts} made, about to make attempt #{attempts + 1}"
end
Throwing ‘:success` or `:failure` from the given block will stop the waiter and return or raise. You can pass a custom message to the throw:
# raises Aws::Waiters::Errors::WaiterFailed
waiter.before_attempt do |attempts|
throw :failure, 'custom-error-message'
end
# cause the waiter to stop polling and return
waiter.before_attempt do |attempts|
throw :success
end
54 55 56 |
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 54 def before_attempt(&block) @before_attempt << block if block_given? end |
#before_wait {|attempts, response| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Register a callback that is invoked after an attempt but before sleeping. Yields the number of attempts made and the previous response.
waiter.before_wait do |attempts, response|
puts "#{attempts} made"
puts response.error.inspect
puts response.data.inspect
end
Throwing ‘:success` or `:failure` from the given block will stop the waiter and return or raise. You can pass a custom message to the throw:
# raises Aws::Waiters::Errors::WaiterFailed
waiter.before_attempt do |attempts|
throw :failure, 'custom-error-message'
end
# cause the waiter to stop polling and return
waiter.before_attempt do |attempts|
throw :success
end
85 86 87 |
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 85 def before_wait(&block) @before_wait << block if block_given? end |
#wait(options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 94 95 96 97 98 |
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 91 def wait() catch(:success) do failure_msg = catch(:failure) do return poll() end raise Errors::WaiterFailed.new(failure_msg || 'waiter failed') end || true end |