I am trying to call this Kotlin suspend code from my Java class. The solution is based on what is mentioned here. https://stackoverflow.com/a/52887677/5140533
Kotlin Code:
Main.kt
suspend fun doWorld() = coroutineScope {
launch {
println("Thread name2 ${Thread.currentThread().name}")
delay(2000L)
println("Hello world")
}
}
@OptIn(DelicateCoroutinesApi::class)
fun doSomethingAsync() =
GlobalScope.future { doWorld() }
Converter.java
public class Converter {
public static void main(String[] args) {
MainKt.doSomethingAsync();
}
}
When I call doSomethingAsync() from my Java class, I do not see any of the print statements. Can somebody please explain what exactly is going on and how I can correct this.