Travis Griggs
02/22/2024, 7:15 PMCoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch { runTheSuspendFunction() }
But I was reading the documentation and saw this line in there:
Manual implementation of this interface is not recommended, implementation by delegation should be preferred instead.Which leads me to ask... am I doing something I ought not? Is there a more preferred way to do this?
kevin.cianfarini
02/22/2024, 7:23 PMrunTheSuspendFunction
.
Rather than pulling a coroutine scope out of thin air like you’re doing, you should:
class SomeThing {
val scope = CoroutineScope(...)
fun runFunctionAsync() {
scope.launch(<http://Dispatchers.IO|Dispatchers.IO>) { runTheSuspendFunction() }
}
fun close() = scope.cancel()
}
kevin.cianfarini
02/22/2024, 7:24 PMclose
), or the lifetime of platform thing like a ViewModel or a compose effect.