Sha256: 5ab1eab5e6f461ec69511df2fa440f7ceeda52dac8982ab914737aa8513a3e4f

Contents?: true

Size: 1.05 KB

Versions: 21

Compression:

Stored size: 1.05 KB

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 clear
          ret = @stash.dup
          @stash.clear
          ret
        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

21 entries across 21 versions & 1 rubygems

Version Path
dynflow-0.8.16 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.15 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.14 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.13 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.12 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.11 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.10 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.9 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.8 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.7 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.6 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.5 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.4 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.3 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.2 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.1 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.8.0 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.7.9 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.7.8 lib/dynflow/executors/parallel/work_queue.rb
dynflow-0.7.7 lib/dynflow/executors/parallel/work_queue.rb