Class: EventMachine::Ventually::Pool
- Inherits:
-
Object
- Object
- EventMachine::Ventually::Pool
- Defined in:
- lib/em-ventually/pool.rb
Instance Method Summary collapse
- #complete(e) ⇒ Object
- #empty? ⇒ Boolean
- #in_parallel ⇒ Object
-
#initialize ⇒ Pool
constructor
A new instance of Pool.
- #push(e) ⇒ Object
- #should_run?(eventually) ⇒ Boolean
Constructor Details
#initialize ⇒ Pool
Returns a new instance of Pool.
4 5 6 |
# File 'lib/em-ventually/pool.rb', line 4 def initialize @store = [] end |
Instance Method Details
#complete(e) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/em-ventually/pool.rb', line 32 def complete(e) if @store.first.is_a?(Array) @store.first.delete(e) @store.shift if @store.last.empty? else @store.delete(e) end end |
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/em-ventually/pool.rb', line 41 def empty? @store.empty? end |
#in_parallel ⇒ Object
17 18 19 20 |
# File 'lib/em-ventually/pool.rb', line 17 def in_parallel @store.push [] yield end |
#push(e) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/em-ventually/pool.rb', line 22 def push(e) if @store.last.is_a?(Array) @store.last.last.run unless @store.last.last.nil? @store.last.push(e) else @store.last.run unless @store.last.nil? @store.push(e) end end |
#should_run?(eventually) ⇒ Boolean
8 9 10 11 12 13 14 15 |
# File 'lib/em-ventually/pool.rb', line 8 def should_run?(eventually) case @store.first when Array @store.first.include?(eventually) else @store.first == eventually end end |