Class: SuperPoller::QueueIterator
- Inherits:
-
Object
- Object
- SuperPoller::QueueIterator
- Defined in:
- lib/super_poller/queue_iterator.rb
Instance Method Summary collapse
- #destroy_the_memo ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(queue) ⇒ QueueIterator
constructor
A new instance of QueueIterator.
Constructor Details
#initialize(queue) ⇒ QueueIterator
Returns a new instance of QueueIterator.
2 3 4 |
# File 'lib/super_poller/queue_iterator.rb', line 2 def initialize(queue) @queue = queue end |
Instance Method Details
#destroy_the_memo ⇒ Object
25 26 27 28 29 |
# File 'lib/super_poller/queue_iterator.rb', line 25 def destroy_the_memo while @memo and msg = @queue.fetch and msg != @memo @queue.push(msg) end end |
#each(&block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/super_poller/queue_iterator.rb', line 6 def each(&block) @memo = {:memo => Time.now.to_f} @queue.push @memo while @memo begin break unless msg = @queue.fetch if msg == @memo msg = @memo = nil else msg = nil if :delete == block.call(msg) end ensure @queue.push msg if msg end end ensure destroy_the_memo end |