Class: Core::Async::Future
- Inherits:
-
Object
- Object
- Core::Async::Future
- Defined in:
- lib/core/async/future.rb
Overview
- public
-
Represents a future result.
Instance Method Summary collapse
-
#complete? ⇒ Boolean
- public
-
Return
trueif complete.
-
#error ⇒ Object
- public
-
Return any error that occurred without re-raising, blocking until available.
-
#failed? ⇒ Boolean
- public
-
Return
trueif failed.
-
#initialize(task) ⇒ Future
constructor
A new instance of Future.
-
#pending? ⇒ Boolean
- public
-
Return
trueif pending.
-
#resolved? ⇒ Boolean
- public
-
Return
trueif failed or complete.
-
#result ⇒ Object
- public
-
Return the result, blocking until available.
-
#status ⇒ Object
- public
-
Return the status; one of :pending, :failed, or :complete.
-
#wait ⇒ Object
- public
-
Wait on the task to complete, returning self.
Constructor Details
#initialize(task) ⇒ Future
Returns a new instance of Future.
8 9 10 11 |
# File 'lib/core/async/future.rb', line 8 def initialize(task) @task = task @error = nil end |
Instance Method Details
#complete? ⇒ Boolean
- public
-
Return
trueif complete.
96 97 98 |
# File 'lib/core/async/future.rb', line 96 def complete? status == :complete end |
#error ⇒ Object
- public
-
Return any error that occurred without re-raising, blocking until available.
41 42 43 |
# File 'lib/core/async/future.rb', line 41 def error @error ||= get_error end |
#failed? ⇒ Boolean
- public
-
Return
trueif failed.
90 91 92 |
# File 'lib/core/async/future.rb', line 90 def failed? status == :failed end |
#pending? ⇒ Boolean
- public
-
Return
trueif pending.
84 85 86 |
# File 'lib/core/async/future.rb', line 84 def pending? status == :pending end |
#resolved? ⇒ Boolean
- public
-
Return
trueif failed or complete.
102 103 104 |
# File 'lib/core/async/future.rb', line 102 def resolved? failed? || complete? end |
#result ⇒ Object
- public
-
Return the result, blocking until available.
25 26 27 |
# File 'lib/core/async/future.rb', line 25 def result @error || @result ||= resolve end |
#status ⇒ Object
- public
-
Return the status; one of :pending, :failed, or :complete.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/core/async/future.rb', line 54 def status if defined?(@status) @status else status = find_status if terminal_status?(status) @status = status end status end end |
#wait ⇒ Object
- public
-
Wait on the task to complete, returning self.
15 16 17 18 19 20 21 |
# File 'lib/core/async/future.rb', line 15 def wait unless @error resolve end self end |