Class: Promise::Trace

Inherits:
Promise show all
Defined in:
opal/stdlib/promise.rb

Instance Attribute Summary

Attributes inherited from Promise

#error, #next, #prev, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Promise

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

Constructor Details

#initialize(block) ⇒ Trace

Returns a new instance of Trace



212
213
214
215
216
# File 'opal/stdlib/promise.rb', line 212

def initialize(block)
  super -> {
    block.call(*Trace.it(self).reverse)
  }
end

Class Method Details

.it(promise) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'opal/stdlib/promise.rb', line 198

def self.it(promise)
  unless promise.realized?
    raise ArgumentError, "the promise hasn't been realized"
  end

  current = promise.act? ? [promise.value] : []

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