Class: Promise::Trace

Inherits:
Promise show all
Defined in:
opal/stdlib/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, #realized?, #reject, #reject!, #rejected?, #resolve, #resolve!, #resolved?, #then, #then!, #there_can_be_only_one!, #to_v2, #trace, #trace!, #value, value, when

Constructor Details

#initialize(depth, block) ⇒ Trace

Returns a new instance of Trace.



368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'opal/stdlib/promise.rb', line 368

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



353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'opal/stdlib/promise.rb', line 353

def self.it(promise)
  current = []

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

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