Sha256: 41c73d7c2ce1b264fbb4adc36c45d6d533ae0901df3b5760bd6cb49afdbab0e9

Contents?: true

Size: 959 Bytes

Versions: 19

Compression:

Stored size: 959 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 })
    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

19 entries across 19 versions & 1 rubygems

Version Path
bolt-2.15.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.14.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.13.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.12.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.11.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.11.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.10.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.9.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.8.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.7.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.6.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.5.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.4.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.3.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.3.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.2.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.1.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.0.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.0.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb