From 0bc13888e149c61c6dd72caac547c9cc5e5e9c68 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Fri, 14 Jan 2022 16:20:30 +0300 Subject: [PATCH] Explicitly describe undispatched behaviour in runInterruptible Addresses #3109 --- kotlinx-coroutines-core/jvm/src/Interruptible.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kotlinx-coroutines-core/jvm/src/Interruptible.kt b/kotlinx-coroutines-core/jvm/src/Interruptible.kt index b873eadf4a..0bded76517 100644 --- a/kotlinx-coroutines-core/jvm/src/Interruptible.kt +++ b/kotlinx-coroutines-core/jvm/src/Interruptible.kt @@ -8,7 +8,7 @@ import kotlinx.atomicfu.* import kotlin.coroutines.* /** - * Calls the specified [block] with a given coroutine context in a interruptible manner. + * Calls the specified [block] with a given coroutine context in an interruptible manner. * The blocking code block will be interrupted and this function will throw [CancellationException] * if the coroutine is cancelled. * @@ -30,6 +30,11 @@ import kotlin.coroutines.* * suspend fun BlockingQueue.awaitTake(): T = * runInterruptible(Dispatchers.IO) { queue.take() } * ``` + * + * `runInterruptible` uses [withContext] as an underlying mechanism for switching context, + * meaning that the supplied [block] is invoked in an [undispatched][CoroutineStart.UNDISPATCHED] + * manner directly by the caller if [CoroutineDispatcher] from the current [coroutineContext][currentCoroutineContext] + * is the same as the one supplied in [context]. */ public suspend fun runInterruptible( context: CoroutineContext = EmptyCoroutineContext,