lib/bolt/fiber_executor.rb
# Block until the provided PlanFuture objects have finished, or the timeout is reached.
#
Block until the provided PlanFuture objects have finished, or the timeout is reached.
Block until the provided PlanFuture objects have finished or the timeout is reached .
def wait(futures, timeout: nil, catch_errors: false, **_kwargs)
      if futures.nil?
        results = []
        plan_id = get_current_plan_id(fiber: Fiber.current)
        until (futures = get_futures_for_plan(plan_id: plan_id)).map(&:alive?).none?
          if futures.map(&:fiber).include?(Fiber.current)
            msg = "The wait() function cannot be called with no arguments inside a "\
                  "background block in the same plan."
            raise Bolt::Error.new(msg, 'bolt/infinite-wait')
          end
          results = wait(futures, timeout: timeout, catch_errors: catch_errors)
        end
        return results
      end
      if timeout.nil?
        Fiber.yield(:unfinished) until futures.map(&:alive?).none?
      else
        start = Time.now
        Fiber.yield(:unfinished) until (Time.now - start > timeout) || futures.map(&:alive?).none?
        futures.each do |f|
          if f.alive?
            f.raise(Bolt::FutureTimeoutError.new(f.name, timeout))
          end
        end
      end
      results = futures.map(&:value)
      failed_indices = results.each_index.select do |i|
        results[i].is_a?(Bolt::Error)
      end
      if failed_indices.any?
        if catch_errors
          failed_indices.each { |i| results[i] = results[i].to_puppet_error }
        else
          raise Bolt::ParallelFailure.new(results, failed_indices)
        end
      end
      results
    end
def wait ( futures , timeout : nil , catch_errors : false , ** _kwargs ) if futures . nil? results = [ ] plan_id = get_current_plan_id ( fiber : Fiber . current ) until ( futures = get_futures_for_plan ( plan_id : plan_id ) ) . map ( & :alive? ) . none? if futures . map ( & :fiber ) . include? ( Fiber . current ) msg = "The wait() function cannot be called with no arguments inside a " "background block in the same plan." raise Bolt :: Error . new ( msg , 'bolt/infinite-wait' ) end results = wait ( futures , timeout : timeout , catch_errors : catch_errors ) end return results end if timeout . nil? Fiber . yield ( :unfinished ) until futures . map ( & :alive? ) . none? else start = Time . now Fiber . yield ( :unfinished ) until ( Time . now - start > timeout ) || futures . map ( & :alive? ) . none? futures . each do | f | if f . alive? f . raise ( Bolt :: FutureTimeoutError . new ( f . name , timeout ) ) end end end results = futures . map ( & :value ) failed_indices = results . each_index . select do | i | results [ i ] . is_a? ( Bolt :: Error ) end if failed_indices . any? if catch_errors failed_indices . each { | i | results [ i ] = results [ i ] . to_puppet_error } else raise Bolt :: ParallelFailure . new ( results , failed_indices ) end end results end
Block until the provided PlanFuture objects have finished, or the timeout is reached.
Block until the provided PlanFuture objects have finished or the timeout is reached .
# Recollect the futures for this plan until all of the futures have # finished. This ensures that we include futures created inside of # futures being waited on. # Wait for all the futures we know about so far before recollecting # Futures for the plan and waiting again # Raise an error for any futures that are still alive # Do this after handling errors for simplicity and pretty printing
futures
<not_specific>
timeout
<not_specific>
catch_errors
<not_specific>
_kwargs
<not_specific>