Sha256: 55841d7a3e557bbb40aaaea899ce364f00686917c79f66b92018f797216172fb

Contents?: true

Size: 959 Bytes

Versions: 40

Compression:

Stored size: 959 Bytes

Contents

module Dynflow
  class Director
    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

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
dynflow-1.3.0 lib/dynflow/director/work_queue.rb
dynflow-1.2.3 lib/dynflow/director/work_queue.rb
dynflow-1.2.2 lib/dynflow/director/work_queue.rb
dynflow-1.2.1 lib/dynflow/director/work_queue.rb
dynflow-1.2.0 lib/dynflow/director/work_queue.rb
dynflow-1.2.0.pre1 lib/dynflow/director/work_queue.rb
dynflow-1.1.6 lib/dynflow/director/work_queue.rb
dynflow-1.1.5 lib/dynflow/director/work_queue.rb
dynflow-1.1.4 lib/dynflow/director/work_queue.rb
dynflow-1.1.3 lib/dynflow/director/work_queue.rb
dynflow-1.1.2 lib/dynflow/director/work_queue.rb
dynflow-1.1.1 lib/dynflow/director/work_queue.rb
dynflow-1.1.0 lib/dynflow/director/work_queue.rb
dynflow-1.0.5 lib/dynflow/director/work_queue.rb
dynflow-1.0.4 lib/dynflow/director/work_queue.rb
dynflow-1.0.3 lib/dynflow/director/work_queue.rb
dynflow-1.0.2 lib/dynflow/director/work_queue.rb
dynflow-1.0.1 lib/dynflow/director/work_queue.rb
dynflow-1.0.0 lib/dynflow/director/work_queue.rb
dynflow-0.8.37 lib/dynflow/director/work_queue.rb