Class: MapReduce::Queue
- Inherits:
-
Object
- Object
- MapReduce::Queue
- Includes:
- MonitorMixin
- Defined in:
- lib/scrappy/agent/map_reduce.rb
Instance Attribute Summary collapse
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #pop {|item| ... } ⇒ Object
- #push(value) ⇒ Object
- #push_unless_done(value) ⇒ Object
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
11 12 13 14 15 |
# File 'lib/scrappy/agent/map_reduce.rb', line 11 def initialize super @items = [] @history = [] end |
Instance Attribute Details
#history ⇒ Object (readonly)
Returns the value of attribute history.
9 10 11 |
# File 'lib/scrappy/agent/map_reduce.rb', line 9 def history @history end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
9 10 11 |
# File 'lib/scrappy/agent/map_reduce.rb', line 9 def items @items end |
Instance Method Details
#<<(value) ⇒ Object
32 33 34 |
# File 'lib/scrappy/agent/map_reduce.rb', line 32 def << value push value end |
#empty? ⇒ Boolean
44 45 46 |
# File 'lib/scrappy/agent/map_reduce.rb', line 44 def empty? synchronize { @items.empty? } end |
#pop {|item| ... } ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/scrappy/agent/map_reduce.rb', line 17 def pop yielded = false item = nil synchronize do item = @items.shift @history << item if item if @items.empty? yield item if (block_given? and item) yielded = true end end yield item if (block_given? and not yielded) item end |
#push(value) ⇒ Object
36 37 38 |
# File 'lib/scrappy/agent/map_reduce.rb', line 36 def push value synchronize { @items << value } end |
#push_unless_done(value) ⇒ Object
40 41 42 |
# File 'lib/scrappy/agent/map_reduce.rb', line 40 def push_unless_done value synchronize { @items << value if !@history.include?(value) and !@items.include?(value) } end |