dimsuz
02/05/2020, 12:25 PMclass MyClass : CoroutineScope by MainScope() {
fun execute() = launch {
delay(1000)
println("finished")
}
}
fun main() = runBlocking {
val clazz = MyClass()
clazz.execute()
}
This throws an exception:
kotlin.IllegalStateException: There is no event loop. Use runBlocking { ... } to start one.
What do I do wrong?
• If MyClass is external and I can't modify it, how to solve this?
• For some reason if I run the code from the main()
function in Android Activity (which doesn't even have any CouroutineScope), it runs perfectly well. Why?