A Future represents a result of asynchronous execution. It can be used to
block until a value is available or an error has happened, or register a
listener to be notified whenever the execution is complete.
The block can be called synchronously from current thread if the
future has already been resolved, or, asynchronously, from background
thread upon resolution.
The block can be called synchronously from current thread if the
future has already been resolved, or, asynchronously, from background
thread upon resolution.
Run block when future resolves. The block will always be called with 2
arguments - value and error. In case a future resolves to an error, the
error argument will be non-nil.
Note
The block can be called synchronously from current thread if the
future has already been resolved, or, asynchronously, from background
thread upon resolution.
The listener can be notified synchronously, from current thread, if
the future has already been resolved, or, asynchronously, from
background thread upon resolution.
Note
that provided listener doesn’t have to extend
Listener, only conform to the same interface
Future#add_listener raises if listener doesn't respond to #success and #failure
expect(listener).toreceive(:respond_to?).and_return(false)expect{future.add_listener(listener)}.toraise_error(::ArgumentError,"listener must respond to both #success and #failure")
Returns a new future that will resolve to the result of the block.
Besides regular values, block can return other futures, which will be
transparently unwrapped before resolving the future from this method.
Note
The block can be called synchronously from current thread if the
future has already been resolved, or, asynchronously, from background
thread upon resolution.
Examples:
Block returns a value
future_users=session.execute_async('SELECT * FROM users WHERE user_name = ?','Sam')future_user=future_users.then{|users|users.first}
Block returns a future
future_statement=session.prepare_async('SELECT * FROM users WHERE user_name = ?')future_users=future_statement.then{|statement|session.execute_async(statement,'Sam')}
Returns a new future that will resolve to the result of the block in case
of an error. Besides regular values, block can return other futures,
which will be transparently unwrapped before resolving the future from
this method.
Note
The block can be called synchronously from current thread if the
future has already been resolved, or, asynchronously, from background
thread upon resolution.
Examples:
Recovering from errors
future_error=session.execute_async('SELECT * FROM invalid-table')future=future_error.fallback{|error|"Execution failed with #{error.class.name}: #{error.message}"}
Executing something else on error
future_error=session.execute_async('SELECT * FROM invalid-table')future=future_error.fallback{|e|session.execute_async('SELECT * FROM another-table')}
This method blocks until a future is resolved or a times out
Parameters:
Name
Type
Details
timeout
(nil or Numeric)
(defaults to: nil)
a maximum number of seconds to block
current thread for while waiting for this future to resolve. Will
wait indefinitely if passed nil.