Class: Cql::CompletableFuture
Direct Known Subclasses
Instance Method Summary collapse
Methods inherited from Future
#completed?, #failed?, #initialize, #resolved?, #value
Methods included from FutureFactories
#all, #failed, #first, #resolved
Methods included from FutureCallbacks
#on_complete, #on_failure, #on_value
Methods included from FutureCombinators
#fallback, #flat_map, #map, #recover
Constructor Details
This class inherits a constructor from Cql::Future
Instance Method Details
#fail(error) ⇒ Object
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/cql/future.rb', line 388 def fail(error) failure_listeners = nil complete_listeners = nil @lock.synchronize do raise FutureError, 'Future already completed' if @failed || @resolved @failed = true @error = error failure_listeners = @failure_listeners complete_listeners = @complete_listeners @value_listeners = nil @failure_listeners = nil @complete_listeners = nil end failure_listeners.each do |listener| listener.call(error) rescue nil end complete_listeners.each do |listener| listener.call(self) rescue nil end nil end |
#resolve(v = nil) ⇒ Object
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/cql/future.rb', line 366 def resolve(v=nil) value_listeners = nil complete_listeners = nil @lock.synchronize do raise FutureError, 'Future already completed' if @resolved || @failed @resolved = true @value = v value_listeners = @value_listeners complete_listeners = @complete_listeners @value_listeners = nil @failure_listeners = nil @complete_listeners = nil end value_listeners.each do |listener| listener.call(v) rescue nil end complete_listeners.each do |listener| listener.call(self) rescue nil end nil end |