Sha256: 2e1bb7e2d322ad58c6ec12444dfc7cad3e0287f2c06bda2cb5c4e0fbec80fb00

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 KB

Contents

module Mutant
  module Parallel
    # Job source for parallel execution
    class Source
      include AbstractType

      NoJobError = Class.new(RuntimeError)

      # Next job
      #
      # @return [Object]
      #
      # @raise [NoJobError]
      #   when no next job is available
      abstract_method :next

      # Test if next job is available
      #
      # @return [Boolean]
      abstract_method :next?

      # Job source backed by a finite array
      class Array
        include Concord.new(:jobs)

        # Initialize objecto
        #
        # @return [undefined]
        def initialize(*)
          super

          @next_index = 0
        end

        # Test if next job is available
        #
        # @return [Boolean]
        def next?
          @next_index < jobs.length
        end

        # Next job
        #
        # @return [Object]
        #
        # @raise [NoJobError]
        #   when no next job is available
        def next
          fail NoJobError unless next?
          jobs.fetch(@next_index).tap do
            @next_index += 1
          end
        end

      end # Array
    end # Source
  end # Parallel
end # Mutant

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mutant-0.8.16 lib/mutant/parallel/source.rb
mutant-0.8.15 lib/mutant/parallel/source.rb
mutant-0.8.14 lib/mutant/parallel/source.rb
mutant-0.8.13 lib/mutant/parallel/source.rb
mutant-0.8.12 lib/mutant/parallel/source.rb
mutant-0.8.11 lib/mutant/parallel/source.rb
mutant-0.8.10 lib/mutant/parallel/source.rb
mutant-0.8.9 lib/mutant/parallel/source.rb