class Arachni::Reactor::Queue
@note Pretty much an `EventMachine::Queue` rip-off.
A cross thread, {Reactor#schedule Reactor
scheduled}, linear queue.
This class provides a simple queue abstraction on top of the {Reactor#schedule scheduler}.
It services two primary purposes:
-
API sugar for stateful protocols.
-
Pushing processing onto the {Reactor#thread reactor thread}.
@author Tasos “Zapotek” Laskos <tasos.laskos@gmail.com>
Attributes
reactor[R]
@return [Reactor]
Public Class Methods
new( reactor )
click to toggle source
@param [Reactor] reactor
# File lib/arachni/reactor/queue.rb, line 32 def initialize( reactor ) @reactor = reactor @items = [] @waiting = [] end
Public Instance Methods
empty?()
click to toggle source
@note This is a peek, it's not thread safe, and may only tend toward accuracy.
@return [Boolean]
# File lib/arachni/reactor/queue.rb, line 68 def empty? @items.empty? end
num_waiting()
click to toggle source
@note Accuracy cannot be guaranteed.
@return [Integer]
Number of jobs that are currently waiting on the Queue for items to appear.
# File lib/arachni/reactor/queue.rb, line 84 def num_waiting @waiting.size end
pop( &block )
click to toggle source
@param [Block] block
Block to be {Reactor#schedule scheduled} by the {Reactor} and passed an item from the queue as soon as one becomes available.
# File lib/arachni/reactor/queue.rb, line 41 def pop( &block ) @reactor.schedule do if @items.empty? @waiting << block else block.call @items.shift end end nil end
push( item )
click to toggle source
@param [Object] item
{Reactor#schedule Schedules} an item for addition to the queue.
# File lib/arachni/reactor/queue.rb, line 55 def push( item ) @reactor.schedule do @items.push( item ) @waiting.shift.call @items.shift until @items.empty? || @waiting.empty? end nil end
Also aliased as: <<
size()
click to toggle source
@note This is a peek, it's not thread safe, and may only tend toward accuracy.
@return [Integer]
Queue size.
# File lib/arachni/reactor/queue.rb, line 76 def size @items.size end