@@ -56,22 +56,38 @@ public actual object Dispatchers {
5656
5757 /* *
5858 * 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
6060 * 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+ *
6383 *
6484 * Note, that if you need your coroutine to be confined to a particular thread or a thread-pool after resumption,
6585 * but still want to execute it in the current call-frame until its first suspension, then you can use
6686 * an optional [CoroutineStart] parameter in coroutine builders like
6787 * [launch][CoroutineScope.launch] and [async][CoroutineScope.async] setting it to the
6888 * 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.
7289 */
7390 @JvmStatic
74- @ExperimentalCoroutinesApi
7591 public actual val Unconfined : CoroutineDispatcher = kotlinx.coroutines.Unconfined
7692
7793 /* *
0 commit comments