On trying to run this code in playground: <https:/...
# coroutines
a
On trying to run this code in playground: https://pl.kotl.in/r1dZNoYIE, it says "No main method found in project". However, on uncommenting
await()
on both, it runs. Is this a bug with the playground?
g
looks like a type inference problem,
await
is causing
runBlocking
to return
Unit
, where before its returning
Deferred<Unit>
.
try writing
fun main() = runBlocking<Unit> {
....
👍 1
b
Usually the IDE would mark the function as unused. Beyond that, type inference on the main function has almost always been confusing one way or another
a
I think main can be a suspend fun starting with a recent version of Kotlin
b
Yes, Kotlin 1.3
g
Yes, but it’s not exactly the same, you cannot use coroutine builders like launch/async without runBlocking or coroutineContext