Skip to content

Commit c4cd1fd

Browse files
authored
Update withContext KDoc (#3309)
Fixes #3167
1 parent aedbcc7 commit c4cd1fd

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,15 @@ private class LazyDeferredCoroutine<T>(
126126
* This suspending function is cancellable. It immediately checks for cancellation of
127127
* the resulting context and throws [CancellationException] if it is not [active][CoroutineContext.isActive].
128128
*
129-
* This function uses dispatcher from the new context, shifting execution of the [block] into the
130-
* different thread if a new dispatcher is specified, and back to the original dispatcher
131-
* when it completes. Note that the result of `withContext` invocation is
132-
* dispatched into the original context in a cancellable way with a **prompt cancellation guarantee**,
133-
* which means that if the original [coroutineContext], in which `withContext` was invoked,
134-
* is cancelled by the time its dispatcher starts to execute the code,
129+
* Calls to [withContext] whose [context] argument provides a [CoroutineDispatcher] that is
130+
* different from the current one, by necessity, perform additional dispatches: the [block]
131+
* can not be executed immediately and needs to be dispatched for execution on
132+
* the passed [CoroutineDispatcher], and then when the [block] completes, the execution
133+
* has to shift back to the original dispatcher.
134+
*
135+
* Note that the result of `withContext` invocation is dispatched into the original context in a cancellable way
136+
* with a **prompt cancellation guarantee**, which means that if the original [coroutineContext]
137+
* in which `withContext` was invoked is cancelled by the time its dispatcher starts to execute the code,
135138
* it discards the result of `withContext` and throws [CancellationException].
136139
*
137140
* The cancellation behaviour described above is enabled if and only if the dispatcher is being changed.

0 commit comments

Comments
 (0)