Skip to content

Commit 391042f

Browse files
committed
Promote isDispatchNeeded to stable API
1 parent 445e026 commit 391042f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

kotlinx-coroutines-core/common/src/CoroutineDispatcher.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import kotlin.coroutines.*
2727
*
2828
* This class ensures that debugging facilities in [newCoroutineContext] function work properly.
2929
*/
30-
public abstract class CoroutineDispatcher
31-
: AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
30+
public abstract class CoroutineDispatcher :
31+
AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
3232

3333
/**
3434
* Returns `true` if the execution of the coroutine should be performed with [dispatch] method.
@@ -40,19 +40,18 @@ public abstract class CoroutineDispatcher
4040
*
4141
* A dispatcher can override this method to provide a performance optimization and avoid paying a cost of an unnecessary dispatch.
4242
* 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.
4547
*
4648
* Coroutine builders like [launch][CoroutineScope.launch] and [async][CoroutineScope.async] accept an optional [CoroutineStart]
4749
* parameter that allows one to optionally choose the [undispatched][CoroutineStart.UNDISPATCHED] behavior to start coroutine immediately,
4850
* but to be resumed only in the provided dispatcher.
4951
*
5052
* This method should generally be exception-safe. An exception thrown from this method
5153
* 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`.
5454
*/
55-
@ExperimentalCoroutinesApi
5655
public open fun isDispatchNeeded(context: CoroutineContext): Boolean = true
5756

5857
/**

0 commit comments

Comments
 (0)