Module: Concurrent::Obligation
- Includes:
- Dereferenceable
- Defined in:
- lib/concurrent/obligation.rb
Instance Method Summary collapse
- #completed? ⇒ Boolean
- #exception(*args) ⇒ Object
-
#fulfilled? ⇒ Boolean
(also: #realized?)
Has the obligation been fulfilled?.
- #incomplete? ⇒ Boolean
-
#no_error!(timeout = nil) ⇒ Obligation
wait until Obligation is #complete?.
-
#pending? ⇒ Boolean
Is obligation completion still pending?.
- #reason ⇒ Object
-
#rejected? ⇒ Boolean
Has the obligation been rejected?.
- #state ⇒ Object
-
#unscheduled? ⇒ Boolean
Is the obligation still unscheduled?.
-
#value(timeout = nil) ⇒ Object
See Dereferenceable#deref.
-
#value!(timeout = nil) ⇒ Object
See Dereferenceable#deref.
-
#wait(timeout = nil) ⇒ Obligation
wait until Obligation is #complete?.
Instance Method Details
#completed? ⇒ Boolean
37 38 39 |
# File 'lib/concurrent/obligation.rb', line 37 def completed? [:fulfilled, :rejected].include? state end |
#exception(*args) ⇒ Object
95 96 97 98 |
# File 'lib/concurrent/obligation.rb', line 95 def exception(*args) raise 'obligation is not rejected' unless rejected? reason.exception(*args) end |
#fulfilled? ⇒ Boolean Also known as: realized?
Has the obligation been fulfilled?
14 15 16 |
# File 'lib/concurrent/obligation.rb', line 14 def fulfilled? state == :fulfilled end |
#incomplete? ⇒ Boolean
41 42 43 |
# File 'lib/concurrent/obligation.rb', line 41 def incomplete? [:unscheduled, :pending].include? state end |
#no_error!(timeout = nil) ⇒ Obligation
wait until Obligation is #complete?
63 64 65 |
# File 'lib/concurrent/obligation.rb', line 63 def no_error!(timeout = nil) wait(timeout).tap { raise self if rejected? } end |
#pending? ⇒ Boolean
Is obligation completion still pending?
27 28 29 |
# File 'lib/concurrent/obligation.rb', line 27 def pending? state == :pending end |
#reason ⇒ Object
85 86 87 88 89 90 |
# File 'lib/concurrent/obligation.rb', line 85 def reason mutex.lock @reason ensure mutex.unlock end |
#rejected? ⇒ Boolean
Has the obligation been rejected?
21 22 23 |
# File 'lib/concurrent/obligation.rb', line 21 def rejected? state == :rejected end |
#state ⇒ Object
78 79 80 81 82 83 |
# File 'lib/concurrent/obligation.rb', line 78 def state mutex.lock @state ensure mutex.unlock end |
#unscheduled? ⇒ Boolean
Is the obligation still unscheduled?
33 34 35 |
# File 'lib/concurrent/obligation.rb', line 33 def unscheduled? state == :unscheduled end |
#value(timeout = nil) ⇒ Object
Returns see Dereferenceable#deref.
46 47 48 49 |
# File 'lib/concurrent/obligation.rb', line 46 def value(timeout = nil) wait timeout deref end |
#value!(timeout = nil) ⇒ Object
Returns see Dereferenceable#deref.
69 70 71 72 73 74 75 76 |
# File 'lib/concurrent/obligation.rb', line 69 def value!(timeout = nil) wait(timeout) if rejected? raise self else deref end end |
#wait(timeout = nil) ⇒ Obligation
wait until Obligation is #complete?
54 55 56 57 |
# File 'lib/concurrent/obligation.rb', line 54 def wait(timeout = nil) event.wait(timeout) if timeout != 0 && incomplete? self end |