Module: Cql::FutureFactories
- Included in:
- Future
- Defined in:
- lib/cql/future.rb
Instance Method Summary collapse
-
#all(*futures) ⇒ Cql::Future<Array>
Combines multiple futures into a new future which resolves when all constituent futures complete, or fails when one or more of them fails.
-
#failed(error) ⇒ Cql::Future
Creates a new pre-failed future.
-
#first(*futures) ⇒ Cql::Future
Returns a future which will be resolved with the value of the first (resolved) of the specified futures.
-
#resolved(value = nil) ⇒ Cql::Future
Creates a new pre-resolved future.
Instance Method Details
#all(*futures) ⇒ Cql::Future<Array>
Combines multiple futures into a new future which resolves when all constituent futures complete, or fails when one or more of them fails.
The value of the combined future is an array of the values of the constituent futures.
90 91 92 93 94 95 96 |
# File 'lib/cql/future.rb', line 90 def all(*futures) if futures.any? CombinedFuture.new(futures) else resolved([]) end end |
#failed(error) ⇒ Cql::Future
Creates a new pre-failed future.
124 125 126 |
# File 'lib/cql/future.rb', line 124 def failed(error) FailedFuture.new(error) end |
#first(*futures) ⇒ Cql::Future
Returns a future which will be resolved with the value of the first (resolved) of the specified futures. If all of the futures fail, the returned future will also fail (with the error of the last failed future).
104 105 106 107 108 109 110 |
# File 'lib/cql/future.rb', line 104 def first(*futures) if futures.any? FirstFuture.new(futures) else resolved end end |
#resolved(value = nil) ⇒ Cql::Future
Creates a new pre-resolved future.
116 117 118 |
# File 'lib/cql/future.rb', line 116 def resolved(value=nil) ResolvedFuture.new(value) end |