Class: Obligation::Base
- Inherits:
-
Object
- Object
- Obligation::Base
- Includes:
- Obligation
- Defined in:
- lib/obligation/impl.rb
Instance Method Summary collapse
- #fulfilled? ⇒ Boolean
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #pending? ⇒ Boolean
- #reason ⇒ Object
- #rejected? ⇒ Boolean
- #state ⇒ Object
- #then ⇒ Object
- #value(timeout = 30) ⇒ Object
Methods included from Obligation
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 |
# File 'lib/obligation/impl.rb', line 8 def initialize @state = :pending @mutex = Mutex.new @event = Concurrent::Event.new @reason = nil end |
Instance Method Details
#fulfilled? ⇒ Boolean
19 20 21 |
# File 'lib/obligation/impl.rb', line 19 def fulfilled? state == :fulfilled end |
#pending? ⇒ Boolean
15 16 17 |
# File 'lib/obligation/impl.rb', line 15 def pending? state == :pending end |
#reason ⇒ Object
31 32 33 |
# File 'lib/obligation/impl.rb', line 31 def reason @mutex.synchronize { @reason } end |
#rejected? ⇒ Boolean
23 24 25 |
# File 'lib/obligation/impl.rb', line 23 def rejected? state == :rejected end |
#state ⇒ Object
27 28 29 |
# File 'lib/obligation/impl.rb', line 27 def state @mutex.synchronize { @state } end |
#then ⇒ Object
39 40 41 42 43 |
# File 'lib/obligation/impl.rb', line 39 def then return self unless block_given? Dependent.new(self, &Proc.new) end |
#value(timeout = 30) ⇒ Object
35 36 37 |
# File 'lib/obligation/impl.rb', line 35 def value(timeout = 30) _value(timeout) end |