Module: EMDextras::Chains

Defined in:
lib/em-dextras/chains.rb

Defined Under Namespace

Modules: Deferrables, SynchronousStage Classes: PipeSetup

Class Method Summary collapse

Class Method Details

.pipe(zero, monitoring, stages, options = {}) ⇒ Object



22
23
24
# File 'lib/em-dextras/chains.rb', line 22

def self.pipe(zero, monitoring, stages, options = {})
  run_chain zero, stages, PipeSetup.new(monitoring, options)
end

.run_chain(input, stages, pipe_setup) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/em-dextras/chains.rb', line 26

def self.run_chain input, stages, pipe_setup
  return if stages.empty?

  stage, *rest = *stages

  puts "Running #{stage}(#{input})" if pipe_setup.options[:debug]

  if stage == :split
    split_chain(input, rest, pipe_setup)
    return
  end


  deferrable = call(stage, input, pipe_setup)
  deferrable.callback do |value|
    run_chain value, rest, pipe_setup
  end
  deferrable.errback do |error_value|
    pipe_setup.inform_exception! error_value, stage
  end
end