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