Maybe something like fun CoroutineScope.startConnection()
(or suspend fun runConnection()
) and add a separate function: suspend fun waitConnected()
? So it could be used like this:
service.startConnection()
service.waitConnected()
// do something
service.disconnect()