I came across <this article> today, which basicall...
# coroutines
g
I came across this article today, which basically recommends to always explicitly switch to
<http://Dispatchers.IO|Dispatchers.IO>
when making network requests. This is something I always wondered if it was worth doing when working with Retrofit suspend functions, or Ktor. What are your thoughts on it?
j
There is absolutely no need to do this.
💯 5
5
Also
Copy code
CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch { .. }
is not how you're supposed to move work around
☝️ 1
g
thats what I thought, thanks.
y
That article, I suspect, is just AI slop. It's wording is very weird, definitely not how any human would describe this situation lol. And its information is wrong or so unclear as to be misleading. In particular: > 3. The Right Way: Always Use
<http://Dispatchers.IO|Dispatchers.IO>
This is just wrong. If a suspend function needs to execute in a specific context, it should swap itself to that context. Any suspend network library will do that automagically (because otherwise what's the point of suspend?)
g
yeah, but it's more than that, I've seen it done in that way in so so many places, I end up doubting myself sometimes
l
Thank @George Z for bringing discussion, and also thank for your explanation @jw @Youssef Shoaib [MOD]. I see those articles may help: • This article from @Manuel Vivo : Coroutines & Patterns for work that shouldn’t be cancelled • This article from Joost @Joost Klitsie (Not sure if this is you 🙂 ) Stop hopping threads!. Sorry guys If I tag you guys wrong time. 🙏
gratitude thank you 1
j
@Leo N yes that is indeed me! 🙂 (only see the mention now) I also commented on the article with a link to the Android docs, where it states that those suspending APIs should be main thread safe
👌 2