2 # A cross thread, reactor scheduled, linear queue.
4 # This class provides a simple "Queue" like abstraction on top of the reactor
5 # scheduler. It services two primary purposes:
6 # * API sugar for stateful protocols
7 # * Pushing processing onto the same thread as the reactor
9 # See examples/ex_queue.rb for a detailed example.
12 # q.push('one', 'two', 'three')
14 # q.pop{ |msg| puts(msg) }
24 # Pop items off the queue, running the block on the reactor thread. The pop
25 # will not happen immediately, but at some point in the future, either in
26 # the next tick, if the queue has data, or when the queue is populated.
28 cb = EM::Callback(*a, &b)
36 nil # Always returns nil
39 # Push items onto the queue in the reactor thread. The items will not appear
40 # in the queue immediately, but will be scheduled for addition during the
45 @popq.shift.call @items.shift until @items.empty? || @popq.empty?
49 # N.B. This is a peek, it's not thread safe, and may only tend toward
55 # N.B. This is a peek, it's not thread safe, and may only tend toward