class Obligation::Base
Public Class Methods
new()
click to toggle source
# File lib/obligation/impl.rb, line 8 def initialize @state = :pending @mutex = Mutex.new @event = Concurrent::Event.new @reason = nil end
Public Instance Methods
fulfilled?()
click to toggle source
# File lib/obligation/impl.rb, line 19 def fulfilled? state == :fulfilled end
pending?()
click to toggle source
# File lib/obligation/impl.rb, line 15 def pending? state == :pending end
reason()
click to toggle source
# File lib/obligation/impl.rb, line 31 def reason @mutex.synchronize { @reason } end
rejected?()
click to toggle source
# File lib/obligation/impl.rb, line 23 def rejected? state == :rejected end
state()
click to toggle source
# File lib/obligation/impl.rb, line 27 def state @mutex.synchronize { @state } end
then()
click to toggle source
# File lib/obligation/impl.rb, line 39 def then return self unless block_given? Dependent.new(self, &Proc.new) end
value(timeout = 30)
click to toggle source
# File lib/obligation/impl.rb, line 35 def value(timeout = 30) _value(timeout) end
Protected Instance Methods
_fulfill(result)
click to toggle source
# File lib/obligation/impl.rb, line 51 def _fulfill(result) @mutex.synchronize { _sync_fulfill result } end
_reject(reason)
click to toggle source
# File lib/obligation/impl.rb, line 65 def _reject(reason) @mutex.synchronize { _sync_reject reason } end
_sync_fulfill(result)
click to toggle source
# File lib/obligation/impl.rb, line 55 def _sync_fulfill(result) if @state == :pending @state = :fulfilled @result = result @event.set else raise StateError.new "Obligation already changed to #{@state}." end end
_sync_pending?()
click to toggle source
# File lib/obligation/impl.rb, line 47 def _sync_pending? @state == :pending end
_sync_reject(reason)
click to toggle source
# File lib/obligation/impl.rb, line 69 def _sync_reject(reason) if @state == :pending @state = :rejected @reason = reason @event.set else raise StateError.new "Obligation already changed to #{@state}." end end