Sha256: 8c057674557c2399f5bf6af65884b2090d1dd02577d15b35653bf8abb836e378
Contents?: true
Size: 589 Bytes
Versions: 5
Compression:
Stored size: 589 Bytes
Contents
require 'adrian/queue' module Adrian class ArrayQueue < Adrian::Queue def initialize(array = [], options = {}) super(options) @array = array.map { |item| wrap_item(item) } @mutex = Mutex.new end def pop_item @mutex.synchronize { @array.shift } end def push_item(item) item = wrap_item(item) @mutex.synchronize { @array << item } self end def length @mutex.synchronize { @array.size } end protected def wrap_item(item) item.is_a?(QueueItem) ? item : QueueItem.new(item) end end end
Version data entries
5 entries across 5 versions & 1 rubygems