Module: EMDextras::Chains
- Defined in:
- lib/em-dextras/chains.rb
Defined Under Namespace
Modules: Deferrables, SynchronousStage Classes: InvalidStage, JoinedDeferrable, PipeSetup
Class Method Summary collapse
- .create_chain_result(monitoring, options) ⇒ Object
- .pipe(zero, monitoring, stages, options = {}) ⇒ Object
- .run_chain(input, stages, pipe_setup) ⇒ Object
Class Method Details
.create_chain_result(monitoring, options) ⇒ Object
94 95 96 97 98 |
# File 'lib/em-dextras/chains.rb', line 94 def self.create_chain_result(monitoring, ) EventMachine::DefaultDeferrable.new. tap {|d| d.callback { |value| notify_end_of_chain!(value, monitoring, ) }}. tap {|d| d.errback { |value| notify_end_of_chain!(value, monitoring, ) }} end |
.pipe(zero, monitoring, stages, options = {}) ⇒ Object
89 90 91 92 |
# File 'lib/em-dextras/chains.rb', line 89 def self.pipe(zero, monitoring, stages, = {}) result = create_chain_result(monitoring, ) run_chain zero, stages, PipeSetup.new(monitoring, , result) end |
.run_chain(input, stages, pipe_setup) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/em-dextras/chains.rb', line 100 def self.run_chain input, stages, pipe_setup return pipe_setup.result.succeed(input) if stages.empty? || input.nil? stage, *rest = *stages if stage == :split split_chain(input, rest, pipe_setup) return pipe_setup.result end deferrable = call(stage, input, pipe_setup) check_stage_is_well_behaved!(deferrable, stage, input, deferrable) deferrable.callback do |value| run_chain value, rest, pipe_setup end deferrable.errback do |error_value| pipe_setup.inform_exception! error_value, stage pipe_setup.result.fail(error_value) end pipe_setup.result end |