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

Categories

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

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

1 Answer

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...