class Async::Waterfall
Attributes
blocks[RW]
Public Class Methods
do(&block)
click to toggle source
# File lib/motion-asyncx/async.rb, line 28 def self.do(&block) chain = Waterfall.new chain.blocks << block chain end
new()
click to toggle source
# File lib/motion-asyncx/async.rb, line 4 def initialize @blocks = [] @on_error = nil @on_success = nil @current = 0 end
Public Instance Methods
and_then(&block)
click to toggle source
# File lib/motion-asyncx/async.rb, line 34 def and_then(&block) @blocks << block self end
next_block(previous_result=nil)
click to toggle source
# File lib/motion-asyncx/async.rb, line 11 def next_block(previous_result=nil) block = @blocks[@current] completion = lambda do |result=nil, error=nil| if error @on_error.call(result, error) if @on_error.is_a?(Proc) else @current += 1 if @blocks.length > @current next_block(result) elsif @on_success.is_a?(Proc) @on_success.call(result) end end end block.call(completion, previous_result) end
on_error(&block)
click to toggle source
# File lib/motion-asyncx/async.rb, line 44 def on_error(&block) @on_error = block self end
on_success(&block)
click to toggle source
# File lib/motion-asyncx/async.rb, line 39 def on_success(&block) @on_success = block self end
start()
click to toggle source
# File lib/motion-asyncx/async.rb, line 49 def start next_block() end