Class: Temporal::Middleware::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/temporal/middleware/chain.rb

Instance Method Summary collapse

Constructor Details

#initialize(entries = []) ⇒ Chain

Returns a new instance of Chain.



4
5
6
# File 'lib/temporal/middleware/chain.rb', line 4

def initialize(entries = [])
  @middleware = entries.map(&:init_middleware)
end

Instance Method Details

#invoke(metadata) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/temporal/middleware/chain.rb', line 8

def invoke()
  result = nil
  chain = middleware.dup

  traverse_chain = lambda do
    if chain.empty?
      result = yield
    else
      chain.shift.call(, &traverse_chain)
    end
  end

  traverse_chain.call

  result
end