class Dynflow::Director::WorkQueue
Public Class Methods
new(key_type = Object, work_type = Object)
click to toggle source
# File lib/dynflow/director/work_queue.rb, line 6 def initialize(key_type = Object, work_type = Object) @key_type = key_type @work_type = work_type @stash = Hash.new { |hash, key| hash[key] = [] } end
Public Instance Methods
clear()
click to toggle source
# File lib/dynflow/director/work_queue.rb, line 31 def clear ret = @stash.dup @stash.clear ret end
empty?(key)
click to toggle source
# File lib/dynflow/director/work_queue.rb, line 27 def empty?(key) !present?(key) end
first(key)
click to toggle source
# File lib/dynflow/director/work_queue.rb, line 42 def first(key) return nil if empty?(key) @stash[key].first end
present?(key)
click to toggle source
# File lib/dynflow/director/work_queue.rb, line 23 def present?(key) @stash.key?(key) end
push(key, work)
click to toggle source
# File lib/dynflow/director/work_queue.rb, line 12 def push(key, work) Type! key, @key_type Type! work, @work_type @stash[key].push work end
shift(key)
click to toggle source
# File lib/dynflow/director/work_queue.rb, line 18 def shift(key) return nil unless present? key @stash[key].shift.tap { |work| @stash.delete(key) if @stash[key].empty? } end
size(key)
click to toggle source
# File lib/dynflow/director/work_queue.rb, line 37 def size(key) return 0 if empty?(key) @stash[key].size end