Class: Promise::Trace

Inherits:
Promise
  • Object
show all
Defined in:
lib/hyper-operation/promise.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depth, block) ⇒ Trace

Returns a new instance of Trace.



258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/hyper-operation/promise.rb', line 258

def initialize(depth, block)
  @depth = depth

  super success: proc {
    trace = Trace.it(self).reverse
    trace.pop

    if depth && depth <= trace.length
      trace.shift(trace.length - depth)
    end

    block.call(*trace)
  }
end

Class Method Details

.it(promise) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/hyper-operation/promise.rb', line 244

def self.it(promise)
  current = []

  if promise.act? || promise.prev.nil?
    current.push(promise.value)
  end

  if prev = promise.prev
    current.concat(it(prev))
  else
    current
  end
end