Sha256: dca0bee3393742de39974501458cbea089bd0cac97120fe4fec620ed5aa4c4e0

Contents?: true

Size: 988 Bytes

Versions: 7

Compression:

Stored size: 988 Bytes

Contents

# frozen_string_literal: true

# Repeat the block until it returns a truthy value. Returns the value.
Puppet::Functions.create_function(:'ctrl::do_until') do
  # @param options A hash of additional options.
  # @option options [Numeric] limit The number of times to repeat the block.
  # @example Run a task until it succeeds
  #   ctrl::do_until() || {
  #     run_task('test', $target, _catch_errors => true).ok()
  #   }
  #
  # @example Run a task until it succeeds or fails 10 times
  #   ctrl::do_until('limit' => 10) || {
  #     run_task('test', $target, _catch_errors => true).ok()
  #   }
  #
  dispatch :do_until do
    optional_param 'Hash[String[1], Any]', :options
    block_param
  end

  def do_until(options = { 'limit' => 0 })
    # Send Analytics Report
    Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name)

    limit = options['limit']
    i = 0
    until (x = yield)
      i += 1
      break if limit != 0 && i >= limit
    end
    x
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bolt-2.22.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.21.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.20.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.19.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.18.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.17.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.16.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb