Class: Contrails::Serial

Inherits:
Object
  • Object
show all
Includes:
Chainable
Defined in:
lib/contrails/serial.rb

Instance Method Summary collapse

Methods included from Chainable

#*, #>>, #distribute, included, #run, #to_proc

Constructor Details

#initialize(*procs) ⇒ Serial

Returns a new instance of Serial.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/contrails/serial.rb', line 5

def initialize(*procs)
  @procs = procs
  @procs_with_callbacks = @procs.map {|p| p && p.dup}
  @procs_with_callbacks.zip(@procs_with_callbacks[1..-1]).each do |proc1, proc2|
    if proc2
      proc1.callback {|*args| proc2.call(*args) }
    else
      proc1.callback {|*args| self.succeed(*args)}
    end
  end
end

Instance Method Details

#bind(other) ⇒ Object



17
18
19
# File 'lib/contrails/serial.rb', line 17

def bind(other)
  Contrails::Serial.new(*(@procs + [other]))
end

#call(*args) ⇒ Object



21
22
23
# File 'lib/contrails/serial.rb', line 21

def call(*args)
  @procs_with_callbacks.first.call(*args)
end