@@ -27,8 +27,8 @@ import kotlin.coroutines.*
27
27
*
28
28
* This class ensures that debugging facilities in [newCoroutineContext] function work properly.
29
29
*/
30
- public abstract class CoroutineDispatcher
31
- : AbstractCoroutineContextElement (ContinuationInterceptor ), ContinuationInterceptor {
30
+ public abstract class CoroutineDispatcher :
31
+ AbstractCoroutineContextElement (ContinuationInterceptor ), ContinuationInterceptor {
32
32
33
33
/* *
34
34
* Returns `true` if the execution of the coroutine should be performed with [dispatch] method.
@@ -40,19 +40,18 @@ public abstract class CoroutineDispatcher
40
40
*
41
41
* A dispatcher can override this method to provide a performance optimization and avoid paying a cost of an unnecessary dispatch.
42
42
* E.g. [MainCoroutineDispatcher.immediate] checks whether we are already in the required UI thread in this method and avoids
43
- * an additional dispatch when it is not required. But this method should not return `false` by default, because
44
- * it may expose unexpected behaviour (e.g. with interleaved event-loops) and unexpected order of events.
43
+ * an additional dispatch when it is not required.
44
+ *
45
+ * While this approach can be more efficient, it is not chosen by default to provide a consistent dispatching behaviour
46
+ * so that users won't observe unexpected and non-consistent order of events by default.
45
47
*
46
48
* Coroutine builders like [launch][CoroutineScope.launch] and [async][CoroutineScope.async] accept an optional [CoroutineStart]
47
49
* parameter that allows one to optionally choose the [undispatched][CoroutineStart.UNDISPATCHED] behavior to start coroutine immediately,
48
50
* but to be resumed only in the provided dispatcher.
49
51
*
50
52
* This method should generally be exception-safe. An exception thrown from this method
51
53
* may leave the coroutines that use this dispatcher in the inconsistent and hard to debug state.
52
- *
53
- * **This is an experimental api.** Execution semantics of coroutines may change in the future when this function returns `false`.
54
54
*/
55
- @ExperimentalCoroutinesApi
56
55
public open fun isDispatchNeeded (context : CoroutineContext ): Boolean = true
57
56
58
57
/* *
0 commit comments