Skip to content

Commit 81577b2

Browse files
authored
Clarify withContext(NonCancellable) behavior (#2400)
Fixes #2383
1 parent 31a8df0 commit 81577b2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ private class LazyDeferredCoroutine<T>(
133133
* which means that if the original [coroutineContext], in which `withContext` was invoked,
134134
* is cancelled by the time its dispatcher starts to execute the code,
135135
* it discards the result of `withContext` and throws [CancellationException].
136+
*
137+
* The cancellation behaviour described above is enabled if and only if the dispatcher is being changed.
138+
* For example, when using `withContext(NonCancellable) { ... }` there is no change in dispatcher and
139+
* this call will not be cancelled neither on entry to the block inside `withContext` nor on exit from it.
136140
*/
137141
public suspend fun <T> withContext(
138142
context: CoroutineContext,

0 commit comments

Comments
 (0)