https://kotlinlang.org logo
#coroutines
Title
# coroutines
z

Zac Sweers

12/12/2023, 8:04 PM
Edit: Solution in thread 🧵 Was encouraged to bring this here from another slack I am once again wondering if I understand how coroutines work and it's an issue that's stumped a few of us 😅 Trying to add basic parallelization using a parallel mapping function in https://github.com/slackhq/slack-gradle-plugin/pull/678 1. Create new thread pool context: https://github.com/slackhq/slack-gradle-plugin/pull/678/files#diff-a8b4c979f21b3d6249822cd302bc12879d634c30c6c0ddbbd527d6d3299841e1R125 2. that context is passed to the runner: https://github.com/slackhq/slack-gradle-plugin/pull/678/files#diff-a8b4c979f21b3d6249822cd302bc12879d634c30c6c0ddbbd527d6d3299841e1R117 3. context is used in
withContext()
https://github.com/slackhq/slack-gradle-plugin/pull/678/files#diff-8b5029da572289698d8ca52c5bfb70e1c53262375b55c494bbfe916db5e9adc1R75 4. Each rail runs on the same thread despite the context's dispatcher being backed with a n=size thread pool 🤔. Same behavior happens with
<http://Dispatchers.IO|Dispatchers.IO>
and
Dispatchers.Default
too The parallel mapper does work internally as expected (with some fun tests), so I don't think it's an issue with that function directly
@kevin.cianfarini
Solved: problem was the use of
UNDISPATCHED
in the parallel mapper, which ran on the same thread until a suspension point. As the function called in the body wasn't a suspend function, no suspension point ever occurred
👍 4
👍🏾 2