luke
01/29/2020, 2:19 PMContinuation
in my Java code when trying to run async coroutines. Anyone have any resources?diesieben07
01/29/2020, 2:27 PMCompletableFuture
or ListenableFuture
.luke
01/29/2020, 2:28 PMdiesieben07
01/29/2020, 2:28 PMawait
on a CompletableFuture
, etc.)luke
01/29/2020, 2:28 PMluke
01/29/2020, 2:29 PMdiesieben07
01/29/2020, 2:31 PMContinuation
from Java by calling resumeWith
on it, but that could be problematic because that requires an inline-class parameter. You'd have to write a helper method in Kotlin:
fun <T> resumeContinuation(continuation: Continuation<T>, value: T) = continuation.resume(value)
diesieben07
01/29/2020, 2:31 PMdiesieben07
01/29/2020, 2:31 PMresumeWithException
luke
01/29/2020, 2:42 PMObject addresses = geo.reverseGeocodeAsync(location.getLatitude(), location.getLongitude(), 5).await(new Continuation<List<Address>>() {
@NotNull
@Override
public CoroutineContext getContext() {
return GlobalScope.INSTANCE.getCoroutineContext();
}
@Override
public void resumeWith(@NotNull Object o) {
}
});
luke
01/29/2020, 2:43 PMresumeWith
?diesieben07
01/29/2020, 2:49 PMfun myFunctionAsync(): Deferred<Result> {
}
fun myFunctionForJava(callback: Consumer<Result>) {
// adapt deferred to callback here
}
diesieben07
01/29/2020, 2:51 PMluke
01/29/2020, 2:52 PMdiesieben07
01/29/2020, 2:53 PMListenableFuture
. Or just write all your async code in Kotlin Kluke
01/29/2020, 2:54 PMObject
diesieben07
01/29/2020, 2:55 PMsuspend
functions from Java. You need adapters (written in Kotlin) that translate to something Java can handle (like ListenableFuture
)luke
01/29/2020, 2:55 PMghedeon
01/29/2020, 5:10 PM