Skip to content

Instantly share code, notes, and snippets.

@kirich1409
Last active October 12, 2019 13:26
Show Gist options
  • Save kirich1409/d50385e8749abb2d7fe6bc5b5551c2b7 to your computer and use it in GitHub Desktop.
Save kirich1409/d50385e8749abb2d7fe6bc5b5551c2b7 to your computer and use it in GitHub Desktop.
Sample of new AndroidX Concurrent Futures 1.0.0
fun asyncOperation(): ListenableFuture<Foo> {
return CallbackToFutureAdapter.getFuture { completer: CallbackToFutureAdapter.Resolver<Foo> ->
asyncApi.load(object : OnResult {
override fun onSuccess(foo: Foo) {
completer.set(foo);
}
override fun onError(failure: Failure) {
completer.setException(failure.exception);
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment