maybe this is a dumb question but I have to ask.
let's say that I need to run 300 times the decodeFromString in a loop.
Do I need to run this in a suspend function with
withContext
If I don't want to have issues on main thread?
k
kevin.cianfarini
04/06/2023, 1:32 PM
If you want to run this work off the main thread and distribute the work on a multithreaded dispatcher, you should:
Copy code
suspend fun decodeOffMainThread() = withContext(Dispatchers.Default) { /* Your code */ }
// From main thread:
repeat(300) {
coroutineScope.launch {
decodeOffMainThead()
}
}
It’s not required because that function isn’t suspending.