class Google::Cloud::Env::LazyValue

def await *extra_args, transient_errors: nil, max_tries: 1, max_time: nil, delay_epsilon: 0.0001

Raises:
  • (Exception) - if a fatal error happened, or retries have been

Returns:
  • (Object) - the value

Parameters:
  • delay_epsilon (Numeric) -- An extra delay in seconds to ensure
  • max_time (Numeric, nil) -- The maximum time in seconds this will
  • max_tries (Integer, nil) -- The maximum number of times this will
  • transient_errors (Array) -- An array of exception classes
  • extra_args (Array) -- extra arguments to pass to the block
def await *extra_args, transient_errors: nil, max_tries: 1, max_time: nil, delay_epsilon: 0.0001
  transient_errors ||= [StandardError]
  transient_errors = Array transient_errors
  expiry_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + max_time if max_time
  begin
    get(*extra_args)
  rescue *transient_errors
    # A snapshot of the state. It is possible that another thread has
    # changed this state since we received the error. This is okay
    # because our specification for this method is conservative:
    # whatever we return will have been correct at some point.
    state = internal_state
    # Don't retry unless we're in a state where retries can happen.
    raise if [:failed, :success].include? state[0]
    if max_tries
      # Handle retry countdown
      max_tries -= 1
      raise unless max_tries.positive?
    end
    # Determine the next delay
    delay = determine_await_retry_delay state, expiry_time, delay_epsilon
    # nil means we've exceeded the max time
    raise if delay.nil?
    sleep delay if delay.positive?
    retry
  end
end