Sha256: 85d1bed7eb598cdd6fea823f0083a914527e733c570a818f8c2e50b6147a5715

Contents?: true

Size: 976 Bytes

Versions: 15

Compression:

Stored size: 976 Bytes

Contents

module Dynflow
  module Executors
    class Parallel < Abstract
      class WorkQueue
        include Algebrick::TypeCheck

        def initialize(key_type = Object, work_type = Object)
          @key_type  = key_type
          @work_type = work_type
          @stash     = Hash.new { |hash, key| hash[key] = [] }
        end

        def push(key, work)
          Type! key, @key_type
          Type! work, @work_type
          @stash[key].push work
        end

        def shift(key)
          return nil unless present? key
          @stash[key].shift.tap { |work| @stash.delete(key) if @stash[key].empty? }
        end

        def present?(key)
          @stash.key?(key)
        end

        def empty?(key)
          !present?(key)
        end

        def size(key)
          return 0 if empty?(key)
          @stash[key].size
        end

        def first(key)
          return nil if empty?(key)
          @stash[key].first
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
dynflow-0.7.5 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.7.4 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.7.3 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.7.2 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.7.1 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.7.0 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.6.2 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.6.1 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.6.0 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.5.1 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.5.0 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.4.1 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.4.0 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.3.0 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.2.0 lib/dynflow/executors/parallel/work_queue.rb