Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

java - Is it possible to chain async calls using Guava?

I want to chain async rest service calls and have single callback when they finished.

Is it possible to do it with guava?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Futures.chain was removed in version 12.0. The new method of chaining together ListenableFutures is via the Futures.transform method.

https://github.com/google/guava/wiki/ListenableFutureExplained#application

From Guava latest javadoc (16.0.1 as of this writing).

ListenableFuture<RowKey> rowKeyFuture = indexService.lookUp(query);
AsyncFunction<RowKey, QueryResult> queryFunction =
   new AsyncFunction<RowKey, QueryResult>() {
   public ListenableFuture<QueryResult> apply(RowKey rowKey) {
      return dataService.read(rowKey);
   }
};
ListenableFuture<QueryResult> queryFuture = transform(rowKeyFuture, queryFunction);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...