Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

runBlocking can't run regular functions right? Othwerwise what's preventing you from making the main() runblocking and have all functions under a context that allow both types?

If runblocking can't allow non-suspending function then you got a problem because that mean a method implementing an interface can either be suspending or not and therefore for one of two implementation, fail.



You can absolutely do this.

`fun main() = runBlocking<Unit> {`

https://kotlinlang.org/docs/composing-suspending-functions.h...


Then you'll have to explain why that isn't the default main behavior then. Synchronous functions cannot call async functions (without defining N runblocking scopes) but a runblocking main would make kotlin seems color-less and should be seen as best practice. What's the catch?


> would make kotlin seems color-less

Quoting the post:

> Having to mark asynchronous functions with suspend modifier is a small price to pay, but in return you get better insight into your code.

Also you can do `suspend fun main()`




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: