class EventedQueue
Non thread-safe queue working using callbacks usable especially for evented environments such as EventMachine
Attributes
Holds callbacks waiting for value. @return [Array]
Holds values stack. @return [UnifiedQueues::Single]
Public Class Methods
Constructor. @param [UnifiedQueues::Single] stak holder instance wrapped to unified queue
# File lib/evented-queue.rb, line 35 def initialize(stack = UnifiedQueues::Single::new(Array)) @stack = stack @callbacks = [ ] end
Public Instance Methods
Clears the queue.
# File lib/evented-queue.rb, line 108 def clear(&block) result = @stack.clear yield result if not block.nil? return result end
Indicates queue is empty.
@return [Boolean] true
it it is, false
otherwise @yield [Boolean] true
it it is, false
otherwise
# File lib/evented-queue.rb, line 98 def empty?(&block) empty = @stack.empty? yield empty if not block.nil? return empty end
Indicates length of the queue.
@return [Integer] length of the queue @yield [Integer] length of the queue
# File lib/evented-queue.rb, line 85 def length(&block) length = @stack.length yield length if not block.nil? return length end
Pushes value out of the queue.
@return [Object] value from the queue @yield [Object] value from the queue
# File lib/evented-queue.rb, line 66 def pop(&block) if self.empty? @callbacks << block else result = @stack.pop yield result if not block.nil? return result end end
Pushes value into the queue. Priority isn’t supported by default but can be obtained using the stack
argument of constructor by giving priority queue instance.
@param [Object] value value to push @param [Object] key key fo priority purposes @yield [nil]
# File lib/evented-queue.rb, line 50 def push(value, key = value, &block) @stack.push(value, key) if not @callbacks.empty? self.pop &@callbacks.shift end yield if not block.nil? end