Skip to content

Instantly share code, notes, and snippets.

@twogood
Created November 14, 2017 13:56
Show Gist options
  • Save twogood/41d10109a4bc6b5daf7b038bc5308a45 to your computer and use it in GitHub Desktop.
Save twogood/41d10109a4bc6b5daf7b038bc5308a45 to your computer and use it in GitHub Desktop.
Create ListenableFuture<Pair<A, B>> from ListenableFuture<A> and ListenableFuture<B>
fun <A, B> transformAsyncPair(futureA: ListenableFuture<A>, futureB: ListenableFuture<B>, executor: Executor): ListenableFuture<Pair<A, B>> {
return Futures.transformAsync(futureA, AsyncFunction<A, Pair<A, B>> { a ->
Futures.transformAsync(futureB, AsyncFunction<B, Pair<A, B>> { b ->
Futures.immediateFuture(Pair<A, B>(a!!, b!!))
}, executor)
}, executor)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment