Class: EventMachine::Scenario::AdLib

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

Overview

Repeat sequentially an action

Instance Method Summary collapse

Constructor Details

#initialize(times, &block) ⇒ AdLib

Returns a new instance of AdLib.



123
124
125
126
127
128
# File 'lib/scenario/latin.rb', line 123

def initialize times, &block
  @cpt = 0
  @times = times
  @loop = block
  self
end

Instance Method Details

#finally(&block) ⇒ Object



130
131
132
133
# File 'lib/scenario/latin.rb', line 130

def finally &block
  self.callback(&block)
  self.nextStep
end

#nextStepObject



135
136
137
138
139
140
141
142
# File 'lib/scenario/latin.rb', line 135

def nextStep
  if @cpt == @times
    self.succeed
  else
    @loop.call( Proc.new {nextStep}, @cpt)
    @cpt += 1
  end
end