https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

aksh1618

03/03/2019, 7:09 PM
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

groostav

03/03/2019, 7:43 PM
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

bdawg.io

03/03/2019, 8:47 PM
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

ansman

03/03/2019, 9:23 PM
I think main can be a suspend fun starting with a recent version of Kotlin
b

bdawg.io

03/03/2019, 11:08 PM
Yes, Kotlin 1.3
g

gildor

03/04/2019, 6:44 AM
Yes, but it’s not exactly the same, you cannot use coroutine builders like launch/async without runBlocking or coroutineContext
3 Views