class Cassandra::Future::Factory
@private
Public Class Methods
new(executor)
click to toggle source
# File lib/cassandra/future.rb 190 def initialize(executor) 191 @executor = executor 192 end
Public Instance Methods
all(*futures)
click to toggle source
# File lib/cassandra/future.rb 206 def all(*futures) 207 # May get called with varargs or an array of futures. In the latter case, 208 # the first element in futures is the array of futures. Promote it. 209 futures = Array(futures.first) if futures.one? 210 211 # Special case where there are no futures to aggregate. 212 return Value.new([]) if futures.empty? 213 214 monitor = Monitor.new 215 promise = Promise.new(@executor) 216 remaining = futures.length 217 values = Array.new(remaining) 218 219 futures.each_with_index do |future, i| 220 future.on_complete do |v, e| 221 if e 222 promise.break(e) 223 else 224 done = false 225 monitor.synchronize do 226 remaining -= 1 227 done = (remaining == 0) 228 values[i] = v 229 end 230 promise.fulfill(values) if done 231 end 232 end 233 end 234 promise.future 235 end
error(error)
click to toggle source
# File lib/cassandra/future.rb 198 def error(error) 199 Error.new(error) 200 end
promise()
click to toggle source
# File lib/cassandra/future.rb 202 def promise 203 Promise.new(@executor) 204 end
value(value)
click to toggle source
# File lib/cassandra/future.rb 194 def value(value) 195 Value.new(value) 196 end