Class: Google::Cloud::Firestore::Promise::Future
- Inherits:
-
Object
- Object
- Google::Cloud::Firestore::Promise::Future
- Defined in:
- lib/google/cloud/firestore/promise/future.rb
Overview
Future
A Future object represents a value which will become available in future. May reject with a reason instead, e.g. when the tasks raises an exception.
Instance Method Summary collapse
-
#fulfilled? ⇒ Boolean
Is it in fulfilled state?.
-
#initialize(future) ⇒ Future
constructor
Initialize the future object.
-
#reason(timeout = nil, timeout_value = nil) ⇒ Object, timeout_value
Returns reason of future's rejection.
-
#rejected? ⇒ Boolean
Is it in rejected state?.
-
#rescue(*args) {|reason, *args| ... } ⇒ Future
Chains the task to be executed synchronously on executor after it rejects.
-
#then(*args) {|reason, *args| ... } ⇒ Future
Chains the task to be executed synchronously after it fulfills.
-
#value(timeout = nil, timeout_value = nil) ⇒ Object, ...
Method waits for the timeout duration and return the value of the future if fulfilled, timeout value in case of timeout and nil in case of rejection.
-
#wait!(timeout = nil) ⇒ Object
Method waits for the timeout duration and raise exception on rejection.
Constructor Details
#initialize(future) ⇒ Future
Initialize the future object
29 30 31 |
# File 'lib/google/cloud/firestore/promise/future.rb', line 29 def initialize future @future = future end |
Instance Method Details
#fulfilled? ⇒ Boolean
Is it in fulfilled state?
36 37 38 |
# File 'lib/google/cloud/firestore/promise/future.rb', line 36 def fulfilled? @future.fulfilled? end |
#reason(timeout = nil, timeout_value = nil) ⇒ Object, timeout_value
Returns reason of future's rejection.
62 63 64 |
# File 'lib/google/cloud/firestore/promise/future.rb', line 62 def reason timeout = nil, timeout_value = nil @future.reason timeout, timeout_value end |
#rejected? ⇒ Boolean
Is it in rejected state?
43 44 45 |
# File 'lib/google/cloud/firestore/promise/future.rb', line 43 def rejected? @future.rejected? end |
#rescue(*args) {|reason, *args| ... } ⇒ Future
Chains the task to be executed synchronously on executor after it rejects. Does not run the task if it fulfills. It will resolve though, triggering any dependent futures.
90 91 92 |
# File 'lib/google/cloud/firestore/promise/future.rb', line 90 def rescue *args, &task Future.new @future.rescue(*args, &task) end |
#then(*args) {|reason, *args| ... } ⇒ Future
Chains the task to be executed synchronously after it fulfills. Does not run the task if it rejects. It will resolve though, triggering any dependent futures.
80 81 82 |
# File 'lib/google/cloud/firestore/promise/future.rb', line 80 def then *args, &task Future.new @future.then(*args, &task) end |
#value(timeout = nil, timeout_value = nil) ⇒ Object, ...
Method waits for the timeout duration and return the value of the future if fulfilled, timeout value in case of timeout and nil in case of rejection.
55 56 57 |
# File 'lib/google/cloud/firestore/promise/future.rb', line 55 def value timeout = nil, timeout_value = nil @future.value timeout, timeout_value end |
#wait!(timeout = nil) ⇒ Object
Method waits for the timeout duration and raise exception on rejection
70 71 72 |
# File 'lib/google/cloud/firestore/promise/future.rb', line 70 def wait! timeout = nil @future.wait! timeout end |