I saw that the library supports ```<http://Dispatc...
# coroutines
c
I saw that the library supports
Copy code
<http://Dispatchers.IO|Dispatchers.IO> {
    println("Foo")
}
which is the same as
Copy code
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
    println("Foo")
}
Any idea why there are multiple ways to do it, and which one is preferred?
s
Huh! I never knew that. A bit of digging reveals this thread: https://github.com/Kotlin/kotlinx.coroutines/issues/428
I don't love that there are two ways to do the same thing 😞 I think I'll stick to
withContext
1
c
Ahah it's really weird to read about the Coroutines design from before structured concurrency.
j
The first API is cursed
🤣 6
t
is this from kotlin 2? The first option doesn’t work for me 🤔
j
It's not tied to Kotlin version. it's an invoke operator in the kotlinx.coroutines library
c
No, it's old. IDEA doesn't import it by default though, it's
kotlinx.coroutines.import
if you want to try it out. (or, spell it out entirely:)
Copy code
Dispatchers.IO.invoke {
    …
}
t
This did the tricky! I kinda like it 👀
j