module Garcon::Obligation

Public Instance Methods

complete?() click to toggle source

Has the obligation completed processing?

@return [Boolean]

# File lib/garcon/task/obligation.rb, line 67
def complete?
  [:fulfilled, :rejected].include? state
end
exception(*args) click to toggle source

@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
fulfilled?() click to toggle source

Has the obligation been fulfilled?

@return [Boolean]

# File lib/garcon/task/obligation.rb, line 34
def fulfilled?
  state == :fulfilled
end
Also aliased as: realized?
incomplete?() click to toggle source

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
no_error!(timeout = nil)
Alias for: wait!
pending?() click to toggle source

Is obligation completion still pending?

@return [Boolean]

# File lib/garcon/task/obligation.rb, line 51
def pending?
  state == :pending
end
realized?()
Alias for: fulfilled?
reason() click to toggle source

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
rejected?() click to toggle source

Has the obligation been rejected?

@return [Boolean]

# File lib/garcon/task/obligation.rb, line 43
def rejected?
  state == :rejected
end
state() click to toggle source

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
unscheduled?() click to toggle source

Is the obligation still unscheduled?

@return [Boolean]

# File lib/garcon/task/obligation.rb, line 59
def unscheduled?
  state == :unscheduled
end
value(timeout = nil) click to toggle source

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
value!(timeout = nil) click to toggle source

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(timeout = nil) click to toggle source

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!(timeout = nil) click to toggle source

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
Also aliased as: no_error!