Sha256: 967fb0309d07e040b6541df10f13ec929e3a5e269ca7936a15fb70a779565eef

Contents?: true

Size: 1.06 KB

Versions: 25

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Mutant
  module Parallel
    # Driver for parallelized execution
    class Driver
      include Adamantium::Flat, Anima.new(
        :threads,
        :var_active_jobs,
        :var_final,
        :var_sink
      )

      private(*anima.attribute_names)

      # Wait for computation to finish, with timeout
      #
      # @param [Float] timeout
      #
      # @return [Variable::Result<Sink#status>]
      #   current status
      def wait_timeout(timeout)
        var_final.take_timeout(timeout)

        finalize(status)
      end

    private

      def finalize(status)
        status.tap do
          threads.each(&:join) if status.done?
        end
      end

      def status
        var_active_jobs.with do |active_jobs|
          var_sink.with do |sink|
            Status.new(
              active_jobs: active_jobs.dup.freeze,
              done:        threads.all? { |thread| !thread.alive? },
              payload:     sink.status
            )
          end
        end
      end
    end # Driver
  end # Parallel
end # Mutant

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
mutant-0.10.20 lib/mutant/parallel/driver.rb
mutant-0.10.19 lib/mutant/parallel/driver.rb
mutant-0.10.18 lib/mutant/parallel/driver.rb
mutant-0.10.17 lib/mutant/parallel/driver.rb
mutant-0.10.16 lib/mutant/parallel/driver.rb
mutant-0.10.15 lib/mutant/parallel/driver.rb
mutant-0.10.14 lib/mutant/parallel/driver.rb
mutant-0.10.13 lib/mutant/parallel/driver.rb
mutant-0.10.12 lib/mutant/parallel/driver.rb
mutant-0.10.11 lib/mutant/parallel/driver.rb
mutant-0.10.10 lib/mutant/parallel/driver.rb
mutant-0.10.9 lib/mutant/parallel/driver.rb
mutant-0.10.8 lib/mutant/parallel/driver.rb
mutant-0.10.7 lib/mutant/parallel/driver.rb
mutant-0.10.6 lib/mutant/parallel/driver.rb
mutant-0.10.5 lib/mutant/parallel/driver.rb
mutant-0.10.4 lib/mutant/parallel/driver.rb
mutant-0.10.1 lib/mutant/parallel/driver.rb
mutant-0.10.0 lib/mutant/parallel/driver.rb
mutant-0.9.14 lib/mutant/parallel/driver.rb