Class: Hermann::Result
- Inherits:
-
Object
- Object
- Hermann::Result
- Defined in:
- lib/hermann/result.rb
Constant Summary collapse
- STATES =
[:pending, :rejected, :fulfilled, :unfulfilled, ].freeze
Instance Attribute Summary collapse
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#completed? ⇒ Boolean
True if this child can be reaped.
-
#initialize(producer) ⇒ Result
constructor
A new instance of Result.
-
#internal_set_error(exception) ⇒ Object
INTERNAL METHOD ONLY.
-
#internal_set_value(value, is_error) ⇒ Object
INTERNAL METHOD ONLY.
-
#value(timeout = 0) ⇒ NilClass, Object
Access the value of the future.
Constructor Details
#initialize(producer) ⇒ Result
Returns a new instance of Result.
12 13 14 15 16 17 |
# File 'lib/hermann/result.rb', line 12 def initialize(producer) @producer = producer @reason = nil @value = nil @state = :unfulfilled end |
Instance Attribute Details
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
4 5 6 |
# File 'lib/hermann/result.rb', line 4 def reason @reason end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
4 5 6 |
# File 'lib/hermann/result.rb', line 4 def state @state end |
Instance Method Details
#completed? ⇒ Boolean
Returns True if this child can be reaped.
26 27 28 29 |
# File 'lib/hermann/result.rb', line 26 def completed? return true if rejected? || fulfilled? return false end |
#internal_set_error(exception) ⇒ Object
INTERNAL METHOD ONLY. Do not use
This method will set our internal #reason with the details from the exception
67 68 69 70 71 72 |
# File 'lib/hermann/result.rb', line 67 def internal_set_error(exception) return if exception.nil? @reason = exception @state = :rejected end |
#internal_set_value(value, is_error) ⇒ Object
INTERNAL METHOD ONLY. Do not use
This method will be invoked by the underlying extension to indicate set the actual value after a callback has completed
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/hermann/result.rb', line 50 def internal_set_value(value, is_error) @value = value if is_error puts "Hermann::Result#set_internal_value(#{value.class}:\"#{value}\", error?:#{is_error})" @state = :rejected else @state = :fulfilled end end |
#value(timeout = 0) ⇒ NilClass, Object
Access the value of the future
37 38 39 40 |
# File 'lib/hermann/result.rb', line 37 def value(timeout=0) @producer.tick_reactor(timeout) return @value end |