Skip to content

Commit 3d62f64

Browse files
authored
Clarify Dispatchers.IO's implementation note (#2780)
This implementation note mentions that withContext(IO) does not lead to a context switch, which may be misunderstood as a general statement, while it in fact only applies to switches between Default and IO dispatchers. This is one example of misunderstanding: https://stackoverflow.com/questions/68069529/is-kotlinx-coroutines-withcontext-safe-to-use-with-spring-webflux
1 parent 8ba04bc commit 3d62f64

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

kotlinx-coroutines-core/jvm/src/Dispatchers.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ public actual object Dispatchers {
107107
*
108108
* ### Implementation note
109109
*
110-
* This dispatcher shares threads with a [Default][Dispatchers.Default] dispatcher, so using
111-
* `withContext(Dispatchers.IO) { ... }` does not lead to an actual switching to another thread —
112-
* typically execution continues in the same thread.
110+
* This dispatcher shares threads with the [Default][Dispatchers.Default] dispatcher, so using
111+
* `withContext(Dispatchers.IO) { ... }` when already running on the [Default][Dispatchers.Default]
112+
* dispatcher does not lead to an actual switching to another thread — typically execution
113+
* continues in the same thread.
113114
* As a result of thread sharing, more than 64 (default parallelism) threads can be created (but not used)
114115
* during operations over IO dispatcher.
115116
*/

0 commit comments

Comments
 (0)