Hello all.
How do I call a suspend function in Application.kt?
I have a suspend fun and when I call it, an error appears forcing to change the main function to suspend. And if I do that, I can't start the application.
a
Animesh Sahu
02/09/2020, 5:46 AM
if you are using coroutines in your app, it is a good practise to start coroutine fron the main function because it incorporates the coroutine and the dispatcher can be reused.
Try:
Copy code
suspend fun main() = withContext(Dispatchers.Default) {
// put your main's stack here
// here you can call suspend funs
// and thread main is using when suspended
// other coroutine can work on it
// environment is reusable
}
r
Rodrigo Silva
02/09/2020, 2:46 PM
Thanks @Animesh Sahu, but the Ktor does not accept susped fun main. But the Application.module inherits CoroutineScope, so just do