Skip to content

Commit 364ad4c

Browse files
committed
Improve MainCoroutineDispatcher.immediate documentation
Fixes #1219
1 parent b08d61c commit 364ad4c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public abstract class MainCoroutineDispatcher : CoroutineDispatcher() {
2525
* /*
2626
* * If it is known that updateUiElement can be invoked both from the Main thread and from other threads,
2727
* * `immediate` dispatcher is used as a performance optimization to avoid unnecessary dispatch.
28+
* *
29+
* * In that case, when `updateUiElement` is invoked from the Main thread, `uiElement.text` will be
30+
* * invoked immediately without any dispatching, otherwise, the `Dispatchers.Main` dispatch cycle will be triggered.
2831
* */
2932
* withContext(Dispatchers.Main.immediate) {
3033
* uiElement.text = text

ui/kotlinx-coroutines-android/src/HandlerDispatcher.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public sealed class HandlerDispatcher : MainCoroutineDispatcher(), Delay {
3434
* /*
3535
* * If it is known that updateUiElement can be invoked both from the Main thread and from other threads,
3636
* * `immediate` dispatcher is used as a performance optimization to avoid unnecessary dispatch.
37+
* *
38+
* * In that case, when `updateUiElement` is invoked from the Main thread, `uiElement.text` will be
39+
* * invoked immediately without any dispatching, otherwise, the `Dispatchers.Main` dispatch cycle via
40+
* * `Handler.post` will be triggered.
3741
* */
3842
* withContext(Dispatchers.Main.immediate) {
3943
* uiElement.text = text

0 commit comments

Comments
 (0)