require_relative 'logger' module Remon class DedupedQueue include Logger def initialize @hash = {} @mutex = Mutex.new @queue = Queue.new end def enqueue(task) @mutex.synchronize do if @hash[task] logger.debug "duplicate item #{task}" if logger.debug? return end @hash[task] = true end @queue << task end def dequeue(non_block = false) task = @queue.pop(non_block) @mutex.synchronize do @hash.delete task end task end alias_method :'<<', :enqueue alias_method :pop, :dequeue alias_method :shift, :dequeue end end