Has the obligation completed processing?
@return [Boolean]
# File lib/concurrent/concern/obligation.rb, line 47 def complete? [:fulfilled, :rejected].include? state end
Has the obligation completed processing?
@return [Boolean]
@deprecated
# File lib/concurrent/concern/obligation.rb, line 56 def completed? deprecated_method 'completed?', 'complete?' complete? end
@example allows Obligation to be risen
rejected_ivar = Ivar.new.fail raise rejected_ivar
# File lib/concurrent/concern/obligation.rb, line 134 def exception(*args) raise 'obligation is not rejected' unless rejected? reason.exception(*args) end
Has the obligation been fulfilled?
@return [Boolean]
# File lib/concurrent/concern/obligation.rb, line 18 def fulfilled? state == :fulfilled end
Is the obligation still awaiting completion of processing?
@return [Boolean]
# File lib/concurrent/concern/obligation.rb, line 64 def incomplete? ! complete? end
Is obligation completion still pending?
@return [Boolean]
# File lib/concurrent/concern/obligation.rb, line 33 def pending? state == :pending end
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.
@return [Exception] the exception raised during processing or `nil`
# File lib/concurrent/concern/obligation.rb, line 127 def reason mutex.synchronize { @reason } end
Has the obligation been rejected?
@return [Boolean]
# File lib/concurrent/concern/obligation.rb, line 26 def rejected? state == :rejected end
The current state of the obligation.
@return [Symbol] the current state
# File lib/concurrent/concern/obligation.rb, line 118 def state mutex.synchronize { @state } end
Is the obligation still unscheduled?
@return [Boolean]
# File lib/concurrent/concern/obligation.rb, line 40 def unscheduled? state == :unscheduled end
The current value of the obligation. Will be `nil` while the state is pending or the operation has been rejected.
@param [Numeric] timeout the maximum time in seconds to wait. @return [Object] see Dereferenceable#deref
# File lib/concurrent/concern/obligation.rb, line 73 def value(timeout = nil) wait timeout deref end
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).
@param [Numeric] timeout the maximum time in seconds to wait. @return [Object] see Dereferenceable#deref @raise [Exception] raises the reason when rejected
# File lib/concurrent/concern/obligation.rb, line 106 def value!(timeout = nil) wait(timeout) if rejected? raise self else deref end end
Wait until obligation is complete or the timeout has been reached.
@param [Numeric] timeout the maximum time in seconds to wait. @return [Obligation] self
# File lib/concurrent/concern/obligation.rb, line 82 def wait(timeout = nil) event.wait(timeout) if timeout != 0 && incomplete? self end
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).
@param [Numeric] timeout the maximum time in seconds to wait. @return [Obligation] self @raise [Exception] raises the reason when rejected
# File lib/concurrent/concern/obligation.rb, line 94 def wait!(timeout = nil) wait(timeout).tap { raise self if rejected? } end
Atomic compare and set operation State is set to `next_state` only if `current state == expected_current`.
@param [Symbol] next_state @param [Symbol] expected_current
@return [Boolean] true is state is changed, false otherwise
@!visibility private
# File lib/concurrent/concern/obligation.rb, line 182 def compare_and_set_state(next_state, *expected_current) mutex.synchronize do if expected_current.include? @state @state = next_state true else false end end end
@!visibility private
# File lib/concurrent/concern/obligation.rb, line 153 def event @event end
@!visibility private
# File lib/concurrent/concern/obligation.rb, line 142 def get_arguments_from(opts = {}) [*opts.fetch(:args, [])] end
Executes the block within mutex if current state is included in expected_states
@return block value if executed, false otherwise
@!visibility private
# File lib/concurrent/concern/obligation.rb, line 198 def if_state(*expected_states) mutex.synchronize do raise ArgumentError.new('no block given') unless block_given? if expected_states.include? @state yield else false end end end
@!visibility private
# File lib/concurrent/concern/obligation.rb, line 147 def init_obligation(*args) init_mutex(*args) @event = Event.new end
Am I in the current state?
@param [Symbol] expected The state to check against @return [Boolean] true if in the expected state else false
@!visibility private
# File lib/concurrent/concern/obligation.rb, line 218 def ns_check_state?(expected) @state == expected end
@!visibility private
# File lib/concurrent/concern/obligation.rb, line 223 def ns_set_state(value) @state = value end
Generated with the Darkfish Rdoc Generator 2.