Question

In this documentation, it shows an example code for Future<V>, in some GAE datastore ORM's I can see usages for this pattern, what is the implication of using Future on doing datastore put, get or delete methods? What is the common motivation on doing this?

Was it helpful?

Solution

The reason Future is used is because the database operations are done asynchronously, so you can carry on doing whatever and come back to check the result of the database operation.

The implications of an asynchronous store is that you could read a value that is stale, ie a put has been sent but the Future operation is not complete, or worse, the value has already been deleted, but this is something the ORM has hopefully solved for you.

You can use Future.get to block the current thread and wait for the operation to complete and check the result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top