Class: Promise::Trace

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

Instance Attribute Summary

Attributes inherited from Promise

#error, #next, #prev

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Promise

#<<, #>>, #^, #act?, #action, #always, #always!, error, #exception!, #exception?, #fail, #fail!, #inspect, #pending?, #realized?, #reject, #reject!, #rejected?, #resolve, #resolve!, #resolved?, #then, #then!, #there_can_be_only_one!, #trace, #trace!, #value, value, when

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