Module: Concurrent::Concern::Obligation
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Dereferenceable
|
|
Defined in: | lib/concurrent-ruby/concurrent/concern/obligation.rb |
Instance Attribute Summary
-
#complete? ⇒ Boolean
readonly
Has the obligation completed processing?
-
#fulfilled? ⇒ Boolean
(also: #realized?)
readonly
Has the obligation been fulfilled?
-
#incomplete? ⇒ Boolean
readonly
Is the obligation still awaiting completion of processing?
-
#pending? ⇒ Boolean
readonly
Is obligation completion still pending?
-
#realized?
readonly
Alias for #fulfilled?.
-
#rejected? ⇒ Boolean
readonly
Has the obligation been rejected?
-
#state ⇒ Symbol
rw
The current state of the obligation.
-
#unscheduled? ⇒ Boolean
readonly
Is the obligation still unscheduled?
- #state=(value) rw private
Dereferenceable
- Included
#value | Return the value this object represents after applying the options specified by the |
Instance Method Summary
- #exception(*args)
-
#no_error!(timeout = nil)
Alias for #wait!.
-
#reason ⇒ Exception
If an exception was raised during processing this will return the exception object.
-
#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.
-
#compare_and_set_state(next_state, *expected_current) ⇒ Boolean
private
Atomic compare and set operation State is set to
next_state
only ifcurrent state == expected_current
. - #event private
- #get_arguments_from(opts = {}) private
-
#if_state(*expected_states) ⇒ Object
private
Executes the block within mutex if current state is included in expected_states.
- #init_obligation private
-
#ns_check_state?(expected) ⇒ Boolean
private
Am I in the current state?
- #ns_set_state(value) private
- #set_state(success, value, reason) private
Dereferenceable
- Included
Instance Attribute Details
#complete? ⇒ Boolean
(readonly)
Has the obligation completed processing?
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 49
def complete? [:fulfilled, :rejected].include? state end
#fulfilled? ⇒ Boolean
(readonly)
Also known as: #realized?
Has the obligation been fulfilled?
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 20
def fulfilled? state == :fulfilled end
#incomplete? ⇒ Boolean
(readonly)
Is the obligation still awaiting completion of processing?
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 56
def incomplete? ! complete? end
#pending? ⇒ Boolean
(readonly)
Is obligation completion still pending?
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 35
def pending? state == :pending end
#realized? (readonly)
Alias for #fulfilled?.
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 23
alias_method :realized?, :fulfilled?
#rejected? ⇒ Boolean
(readonly)
Has the obligation been rejected?
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 28
def rejected? state == :rejected end
#state ⇒ Symbol
(rw)
The current state of the obligation.
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 110
def state synchronize { @state } end
#state=(value) (rw, private)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 161
def state=(value) synchronize { ns_set_state(value) } end
#unscheduled? ⇒ Boolean
(readonly)
Is the obligation still unscheduled?
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 42
def unscheduled? state == :unscheduled end
Instance Method Details
#compare_and_set_state(next_state, *expected_current) ⇒ Boolean
(private)
Atomic compare and set operation State is set to next_state
only if current state == expected_current
.
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 174
def compare_and_set_state(next_state, *expected_current) synchronize do if expected_current.include? @state @state = next_state true else false end end end
#event (private)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 145
def event @event end
#exception(*args)
#get_arguments_from(opts = {}) (private)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 134
def get_arguments_from(opts = {}) [*opts.fetch(:args, [])] end
#if_state(*expected_states) ⇒ Object (private)
Executes the block within mutex if current state is included in expected_states
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 190
def if_state(*expected_states) synchronize do raise ArgumentError.new('no block given') unless block_given? if expected_states.include? @state yield else false end end end
#init_obligation (private)
[ GitHub ]#no_error!(timeout = nil)
Alias for #wait!.
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 89
alias_method :no_error!, :wait!
#ns_check_state?(expected) ⇒ Boolean
(private)
Am I in the current state?
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 210
def ns_check_state?(expected) @state == expected end
#ns_set_state(value) (private)
[ GitHub ]
#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.
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 119
def reason synchronize { @reason } end
#set_state(success, value, reason) (private)
[ GitHub ]#value(timeout = nil) ⇒ Object
The current value of the obligation. Will be nil
while the state is pending or the operation has been rejected.
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 65
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).
#wait(timeout = nil) ⇒ Obligation
Wait until obligation is complete or the timeout has been reached.
# File 'lib/concurrent-ruby/concurrent/concern/obligation.rb', line 74
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).