module Garcon::Obligation
Public Instance Methods
Has the obligation completed processing?
@return [Boolean]
# File lib/garcon/task/obligation.rb, line 67 def complete? [:fulfilled, :rejected].include? state end
@example allows Obligation
to be risen
rejected_ivar = Ivar.new.fail raise rejected_ivar
# File lib/garcon/task/obligation.rb, line 173 def exception(*args) raise 'obligation is not rejected' unless rejected? reason.exception(*args) end
Has the obligation been fulfilled?
@return [Boolean]
# File lib/garcon/task/obligation.rb, line 34 def fulfilled? state == :fulfilled end
Is the obligation still awaiting completion of processing?
@return [Boolean]
# File lib/garcon/task/obligation.rb, line 75 def incomplete? [:unscheduled, :pending].include? state end
Is obligation completion still pending?
@return [Boolean]
# File lib/garcon/task/obligation.rb, line 51 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/garcon/task/obligation.rb, line 163 def reason mutex.lock @reason ensure mutex.unlock end
Has the obligation been rejected?
@return [Boolean]
# File lib/garcon/task/obligation.rb, line 43 def rejected? state == :rejected end
The current state of the obligation.
@return [Symbol]
The current state.
# File lib/garcon/task/obligation.rb, line 149 def state mutex.lock @state ensure mutex.unlock end
Is the obligation still unscheduled?
@return [Boolean]
# File lib/garcon/task/obligation.rb, line 59 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/garcon/task/obligation.rb, line 88 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.
@raise [Exception]
Raises the reason when rejected.
@return [Object]
see Dereferenceable#deref
# File lib/garcon/task/obligation.rb, line 135 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/garcon/task/obligation.rb, line 100 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 second to wait.
@raise [Exception]
Raises the reason when rejected`
@return [Obligation] self
# File lib/garcon/task/obligation.rb, line 117 def wait!(timeout = nil) wait(timeout).tap { raise self if rejected? } end