Method: Concurrent::Promises::Future#reason

Defined in:
lib/concurrent-ruby/concurrent/promises.rb

#reason(timeout = nil, timeout_value = nil) ⇒ Object, timeout_value

Note:

This function potentially blocks current thread until the Future is resolved. Be careful it can deadlock. Try to chain instead.

Note:

Make sure returned ‘nil` is not confused with timeout, no value when rejected, no reason when fulfilled, etc. Use more exact methods if needed, like AbstractEventFuture#wait, #value!, #result, etc.

Returns reason of future’s rejection. Calls AbstractEventFuture#touch.

Parameters:

  • timeout (Numeric) (defaults to: nil)

    the maximum time in second to wait.

  • timeout_value (Object) (defaults to: nil)

    a value returned by the method when it times out

Returns:

  • (Object, timeout_value)

    the reason, or timeout_value on timeout, or nil on fulfillment.



955
956
957
958
959
960
961
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 955

def reason(timeout = nil, timeout_value = nil)
  if wait_until_resolved timeout
    internal_state.reason
  else
    timeout_value
  end
end