Sha256: 74a8c5c5ee402b2945a0800b5d903cb8117760bfad6c60c4c4bbfd883cd3a558
Contents?: true
Size: 675 Bytes
Versions: 1
Compression:
Stored size: 675 Bytes
Contents
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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
remon-0.1.0 | lib/remon/deduped_queue.rb |