Class: EventMachine::Scenario::Sequence

Inherits:
Object
  • Object
show all
Includes:
EM::Deferrable
Defined in:
lib/scenario/sequence.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Sequence

block must return a deferrable



10
11
12
13
14
15
16
17
# File 'lib/scenario/sequence.rb', line 10

def initialize &block
  @action = []
  @bag = Bag.new
  block.call(@bag).callback do
    @action[0].call
  end
  self
end

Instance Method Details

#then(&block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/scenario/sequence.rb', line 19

def then &block
  size = @action.size + 1
  @bag.incr
  @action << proc {
    defer = block.call(@bag, *@bag[size+1])
    if size < @action.length
      defer.callback { @action[size].call }
    else
      self.succeed
    end
  }
 self
end