【发布时间】:2019-06-18 14:16:10
【问题描述】:
来自某些 SDK 的函数返回给我一个 CompletableFuture。达到该值后如何正确读取该值。
我的代码:
CompletableFuture<Web3ClientVersion> web3clientCompletableFuture;
web3clientCompletableFuture = web3jNode.web3ClientVersion().sendAsync();
sendAsync() 代码(在 SDK 中):
public CompletableFuture<T> sendAsync() {
return web3jService.sendAsync(this, responseType);
}
我可以使用 get() 访问返回的数据,但这会使整个过程同步并阻塞 UI。
我检查了Android API Reference 上的函数签名,例如:
thenApply(Function<? super T, ? extends U> fn)
handle(BiFunction<? super T, Throwable, ? extends U> fn)
但似乎我需要一些代码示例。
[注意:我对 lambda 不是很熟悉]
【问题讨论】:
标签: android completable-future