Module: Concurrent::Concern::Obligation
- Includes:
- Dereferenceable
- Included in:
- Delay, IVar
- Defined in:
- lib/concurrent/concern/obligation.rb
Instance Method Summary (collapse)
-
- (Boolean) complete?
Has the obligation completed processing?.
- - (undocumented) exception(*args)
-
- (Boolean) fulfilled?
(also: #realized?)
Has the obligation been fulfilled?.
-
- (Boolean) incomplete?
Is the obligation still awaiting completion of processing?.
-
- (Boolean) pending?
Is obligation completion still pending?.
-
- (Exception) reason
If an exception was raised during processing this will return the exception object.
-
- (Boolean) rejected?
Has the obligation been rejected?.
-
- (Symbol) state
The current state of the obligation.
-
- (Boolean) unscheduled?
Is the obligation still unscheduled?.
-
- (Object) value(timeout = nil)
The current value of the obligation.
-
- (Object) value!(timeout = nil)
The current value of the obligation.
-
- (Obligation) wait(timeout = nil)
Wait until obligation is complete or the timeout has been reached.
-
- (Obligation) wait!(timeout = nil)
(also: #no_error!)
Wait until obligation is complete or the timeout is reached.
Instance Method Details
- (Boolean) complete?
Has the obligation completed processing?
49 50 51 |
# File 'lib/concurrent/concern/obligation.rb', line 49 def complete? [:fulfilled, :rejected].include? state end |
- (undocumented) exception(*args)
126 127 128 129 |
# File 'lib/concurrent/concern/obligation.rb', line 126 def exception(*args) raise 'obligation is not rejected' unless rejected? reason.exception(*args) end |
- (Boolean) fulfilled? Also known as: realized?
Has the obligation been fulfilled?
20 21 22 |
# File 'lib/concurrent/concern/obligation.rb', line 20 def fulfilled? state == :fulfilled end |
- (Boolean) incomplete?
Is the obligation still awaiting completion of processing?
56 57 58 |
# File 'lib/concurrent/concern/obligation.rb', line 56 def incomplete? ! complete? end |
- (Boolean) pending?
Is obligation completion still pending?
35 36 37 |
# File 'lib/concurrent/concern/obligation.rb', line 35 def pending? state == :pending end |
- (Exception) reason
If an exception was raised during processing this will return the
exception object. Will return nil
when the state is pending or if
the obligation has been successfully fulfilled.
119 120 121 |
# File 'lib/concurrent/concern/obligation.rb', line 119 def reason synchronize { @reason } end |
- (Boolean) rejected?
Has the obligation been rejected?
28 29 30 |
# File 'lib/concurrent/concern/obligation.rb', line 28 def rejected? state == :rejected end |
- (Symbol) state
The current state of the obligation.
110 111 112 |
# File 'lib/concurrent/concern/obligation.rb', line 110 def state synchronize { @state } end |
- (Boolean) unscheduled?
Is the obligation still unscheduled?
42 43 44 |
# File 'lib/concurrent/concern/obligation.rb', line 42 def unscheduled? state == :unscheduled end |
- (Object) value(timeout = nil)
The current value of the obligation. Will be nil
while the state is
pending or the operation has been rejected.
65 66 67 68 |
# File 'lib/concurrent/concern/obligation.rb', line 65 def value(timeout = nil) wait timeout deref end |
- (Object) value!(timeout = nil)
The current value of the obligation. Will be nil
while the state is
pending or the operation has been rejected. Will re-raise any exceptions
raised during processing (but will not raise an exception on timeout).
98 99 100 101 102 103 104 105 |
# File 'lib/concurrent/concern/obligation.rb', line 98 def value!(timeout = nil) wait(timeout) if rejected? raise self else deref end end |
- (Obligation) wait(timeout = nil)
Wait until obligation is complete or the timeout has been reached.
74 75 76 77 |
# File 'lib/concurrent/concern/obligation.rb', line 74 def wait(timeout = nil) event.wait(timeout) if timeout != 0 && incomplete? self end |
- (Obligation) wait!(timeout = nil) Also known as: no_error!
Wait until obligation is complete or the timeout is reached. Will re-raise any exceptions raised during processing (but will not raise an exception on timeout).
86 87 88 |
# File 'lib/concurrent/concern/obligation.rb', line 86 def wait!(timeout = nil) wait(timeout).tap { raise self if rejected? } end |