Oleg Shuliak
10/11/2022, 2:27 PMcoroutineScope {
workflows.forEach {
it.status = formWorkflowActivationStateManager.getCurrentState(it, companyId).toWorkflowStatus()
}
}
I’m wondering if the coroutineScope
is enough to parallel those executions or if I need to use async/await
?Sam
10/11/2022, 2:29 PMasync
— coroutines are sequential by defaultOleg Shuliak
10/11/2022, 2:58 PMSam
10/11/2022, 3:01 PMSam
10/11/2022, 3:01 PMlaunch
, like:
coroutineScope {
workflows.forEach {
launch { it.status = ... }
}
}
The coroutineScope
will wait for all the launched tasks to finish before returning.Oleg Shuliak
10/11/2022, 3:02 PMOleg Shuliak
10/11/2022, 3:06 PMlaunch
will create a parallel task for each entity, right?Sam
10/11/2022, 3:11 PMYoussef Shoaib [MOD]
10/11/2022, 3:14 PMcoroutineScope {
workflows.map { async { it.status = ... } }.awaitAll()
}
Keep in mind that this and launch
will cancel all operations eventually if one fails. If that's not what you want, you can do supervisorScope
instead of coroutineScope
Oleg Shuliak
10/11/2022, 3:17 PM