Marko Mitic

08/15/2019, 10:44 AM
Is there an easy way to call suspend functions from Java 7? I saw some useful APIs in kotlinx-coroutines-jdk8 but that's bit too high for Android


08/15/2019, 10:46 AM
I think the easiest way is to create a non-suspending wrapper function in Kotlin, and then call that function from Java.
👆 1


08/15/2019, 11:27 AM
You need some async abstraction (some promise, future etc) to expose it for Java consumer
Java 7 doesn't have any existing abstractions (except Future, which cannot be used without blocking of the thread), so you need something: guava ListanableFuture, RxJava single etc Alternatively, if you don't want add dependencies to 3rd party libraries, introduce own Promise-like abstraction and write coroutines adapter for it, or just expose this API as simple callback