CFCouchbase SDK
  • Introduction
  • What's New With 2.2.0
  • What's New With 2.0.0
  • About This Book
  • Authors
  • Overview
  • Installation
    • ColdBox Module
    • Traditional Apps
  • Configuration
    • Settings
    • Structure
    • Summary
  • Usage
    • Storing Documents
    • Storage Durability
    • Retrieving Documents
    • Data Serialization
    • Components
      • Auto Inflation
      • Manual Inflation
      • Custom Serialization
      • Binary
    • Custom Transformers
    • Executing Queries
      • View Queries
      • n1ql Queries
      • Query Options
      • Filter Closures
      • Transform Closures
      • Return Types
    • Managing Views
    • Working With Futures
  • Help & Support
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
Export as PDF
  1. Usage

Working With Futures

PreviousManaging ViewsNextHelp & Support

Last updated 7 years ago

Was this helpful?

You have probably noticed that all the asyncronous operations in the SDK return a Java object. This allows control of your application to return immediately to your code without waiting for the remote calls to complete. The future object gives you a window into whats going on and you can elect to monitor the progress on your terms-- deciding how long you're willing to wait-- or ignore it entirely in order to complete the request as quickly as possible.

The most common method is get(). Calling this will instruct your code to wait until th eoperation is complete before continuing. Calling future.get() essentially makes an ansynchronou call syncronous.

future = client.asyncGet( ID = 'brad' );
person = future.get();

OperationFutures are parameterized which means they can each return a different data type from their get(). Check the to see what each asynchronous future returns.

Info Operations are always subject to the timeouts configured for the client regardless of how you interact with the future.

Here are some other methods you can call on a future to handle the response on your terms:

  • cancel() - Cancel this operation, if possible.

  • getStatus() - Get the current status of this operation.

  • isDone() - Whether or not the Operation is done and result can be retrieved with get().

  • get(duration, units) - Get the results of the given operation, but specify how long you're willing to wait.

  • More information on Futures is available here in the Java Docs:

OperationFuture
API Docs
OperationFuture