Module: Garcon::Obligation
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Has the obligation completed processing?.
- #exception(*args) ⇒ Object
-
#fulfilled? ⇒ Boolean
(also: #realized?)
Has the obligation been fulfilled?.
-
#incomplete? ⇒ Boolean
Is the obligation still awaiting completion of processing?.
-
#pending? ⇒ Boolean
Is obligation completion still pending?.
-
#reason ⇒ Exception
If an exception was raised during processing this will return the exception object.
-
#rejected? ⇒ Boolean
Has the obligation been rejected?.
-
#state ⇒ Symbol
The current state of the obligation.
-
#unscheduled? ⇒ Boolean
Is the obligation still unscheduled?.
-
#value(timeout = nil) ⇒ Object
The current value of the obligation.
-
#value!(timeout = nil) ⇒ Object
The current value of the obligation.
-
#wait(timeout = nil) ⇒ Obligation
Wait until obligation is complete or the timeout has been reached.
-
#wait!(timeout = nil) ⇒ Obligation
(also: #no_error!)
Wait until obligation is complete or the timeout is reached.
Instance Method Details
#complete? ⇒ Boolean
Has the obligation completed processing?
67 68 69 |
# File 'lib/garcon/task/obligation.rb', line 67 def complete? [:fulfilled, :rejected].include? state end |
#exception(*args) ⇒ Object
173 174 175 176 |
# File 'lib/garcon/task/obligation.rb', line 173 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?
34 35 36 |
# File 'lib/garcon/task/obligation.rb', line 34 def fulfilled? state == :fulfilled end |
#incomplete? ⇒ Boolean
Is the obligation still awaiting completion of processing?
75 76 77 |
# File 'lib/garcon/task/obligation.rb', line 75 def incomplete? [:unscheduled, :pending].include? state end |
#pending? ⇒ Boolean
Is obligation completion still pending?
51 52 53 |
# File 'lib/garcon/task/obligation.rb', line 51 def pending? state == :pending end |
#reason ⇒ Exception
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.
163 164 165 166 167 168 |
# File 'lib/garcon/task/obligation.rb', line 163 def reason mutex.lock @reason ensure mutex.unlock end |
#rejected? ⇒ Boolean
Has the obligation been rejected?
43 44 45 |
# File 'lib/garcon/task/obligation.rb', line 43 def rejected? state == :rejected end |
#state ⇒ Symbol
The current state of the obligation.
149 150 151 152 153 154 |
# File 'lib/garcon/task/obligation.rb', line 149 def state mutex.lock @state ensure mutex.unlock end |
#unscheduled? ⇒ Boolean
Is the obligation still unscheduled?
59 60 61 |
# File 'lib/garcon/task/obligation.rb', line 59 def unscheduled? state == :unscheduled end |
#value(timeout = nil) ⇒ Object
The current value of the obligation. Will be ‘nil` while the state is pending or the operation has been rejected.
88 89 90 91 |
# File 'lib/garcon/task/obligation.rb', line 88 def value(timeout = nil) wait timeout deref end |
#value!(timeout = nil) ⇒ Object
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).
135 136 137 138 139 140 141 142 |
# File 'lib/garcon/task/obligation.rb', line 135 def value!(timeout = nil) wait(timeout) if rejected? raise self else deref end end |
#wait(timeout = nil) ⇒ Obligation
Wait until obligation is complete or the timeout has been reached.
100 101 102 103 |
# File 'lib/garcon/task/obligation.rb', line 100 def wait(timeout = nil) event.wait(timeout) if timeout != 0 && incomplete? self end |
#wait!(timeout = nil) ⇒ Obligation 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).
117 118 119 |
# File 'lib/garcon/task/obligation.rb', line 117 def wait!(timeout = nil) wait(timeout).tap { raise self if rejected? } end |