class Reference
Constants
- Error
Attributes
reason[R]
state[R]
value[R]
Public Class Methods
new()
click to toggle source
# File lib/reference.rb, line 8 def initialize @state = :pending @on_fulfill_callbacks = [] @on_reject_callbacks = [] @backtrace end
Public Instance Methods
fulfill(value = nil, backtrace = nil)
click to toggle source
# File lib/reference.rb, line 41 def fulfill(value = nil, backtrace = nil) return unless pending? @state = :fulfilled @value = value @backtrace = backtrace run_fulfill_callbacks value end
fulfilled?()
click to toggle source
# File lib/reference.rb, line 19 def fulfilled? @state.equal?(:fulfilled) end
on_fulfill(&callback)
click to toggle source
# File lib/reference.rb, line 27 def on_fulfill(&callback) @on_fulfill_callbacks << callback if fulfilled? run_fulfill_callback(callback) end end
on_reject(&callback)
click to toggle source
# File lib/reference.rb, line 34 def on_reject(&callback) @on_reject_callbacks << callback if rejected? run_reject_callback(callback) end end
pending?()
click to toggle source
# File lib/reference.rb, line 15 def pending? @state.equal?(:pending) end
reject(reason = nil, backtrace = nil)
click to toggle source
# File lib/reference.rb, line 52 def reject(reason = nil, backtrace = nil) return unless pending? @state = :rejected @reason = reason || Error @backtrace = backtrace run_reject_callbacks reason end
rejected?()
click to toggle source
# File lib/reference.rb, line 23 def rejected? @state.equal?(:rejected) end
Private Instance Methods
run_fulfill_callback(callback)
click to toggle source
# File lib/reference.rb, line 73 def run_fulfill_callback(callback) callback.call(@value) end
run_fulfill_callbacks()
click to toggle source
# File lib/reference.rb, line 65 def run_fulfill_callbacks @on_fulfill_callbacks.each { |callback| run_fulfill_callback(callback) } end
run_reject_callback(callback)
click to toggle source
# File lib/reference.rb, line 77 def run_reject_callback(callback) callback.call(@reason) end
run_reject_callbacks()
click to toggle source
# File lib/reference.rb, line 69 def run_reject_callbacks @on_reject_callbacks.each { |callback| run_reject_callback(callback) } end