class EventedQueue

Non thread-safe queue working using callbacks usable especially for evented environments such as EventMachine

Attributes

callbacks[RW]

Holds callbacks waiting for value. @return [Array]

stack[RW]

Holds values stack. @return [UnifiedQueues::Single]

Public Class Methods

new(stack = UnifiedQueues::Single::new(Array)) click to toggle source

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

clear() { |result| ... } click to toggle source

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
Also aliased as: clear!
clear!(&block)
Alias for: clear
empty?() { |empty| ... } click to toggle source

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
length() { |length| ... } click to toggle source

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
pop() { |result| ... } click to toggle source

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
Also aliased as: pop!
pop!(&block)
Alias for: pop
push(value, key = value) { || ... } click to toggle source

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