@@ -56,22 +56,38 @@ public actual object Dispatchers {
56
56
57
57
/* *
58
58
* A coroutine dispatcher that is not confined to any specific thread.
59
- * It executes initial continuation of the coroutine _immediately_ in the current call-frame
59
+ * It executes initial continuation of the coroutine in the current call-frame
60
60
* and lets the coroutine resume in whatever thread that is used by the corresponding suspending function, without
61
- * mandating any specific threading policy.
62
- * **Note: use with extreme caution, not for general code**.
61
+ * mandating any specific threading policy. Nested coroutines launched in this dispatcher form an event-loop to avoid
62
+ * stack overflows.
63
+ *
64
+ * ### Event loop
65
+ * Event loop semantics is a purely internal concept and have no guarantees on the order of execution
66
+ * except that all queued coroutines will be executed on the current thread in the lexical scope of the outermost
67
+ * unconfined coroutine.
68
+ *
69
+ * For example, the following code:
70
+ * ```
71
+ * withContext(Dispatcher.Unconfined) {
72
+ * println(1)
73
+ * withContext(Dispatcher.Unconfined) { // Nested unconfined
74
+ * println(2)
75
+ * }
76
+ * println(3)
77
+ * }
78
+ * println("Done")
79
+ * ```
80
+ * Can print both "1 2 3" and "1 3 2", this is an implementation detail that can be changed.
81
+ * But it is guaranteed that "Done" will be printed only when both `withContext` are completed.
82
+ *
63
83
*
64
84
* Note, that if you need your coroutine to be confined to a particular thread or a thread-pool after resumption,
65
85
* but still want to execute it in the current call-frame until its first suspension, then you can use
66
86
* an optional [CoroutineStart] parameter in coroutine builders like
67
87
* [launch][CoroutineScope.launch] and [async][CoroutineScope.async] setting it to the
68
88
* the value of [CoroutineStart.UNDISPATCHED].
69
- *
70
- * **Note: This is an experimental api.**
71
- * Semantics, order of execution, and particular implementation details of this dispatcher may change in the future.
72
89
*/
73
90
@JvmStatic
74
- @ExperimentalCoroutinesApi
75
91
public actual val Unconfined : CoroutineDispatcher = kotlinx.coroutines.Unconfined
76
92
77
93
/* *
0 commit comments