Skip to content

Commit

Permalink
Explicitly describe undispatched behaviour in runInterruptible (Kotli…
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad authored and yorickhenning committed Jan 28, 2022
1 parent 2ee957b commit 8f40921
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kotlinx-coroutines-core/jvm/src/Interruptible.kt
Expand Up @@ -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.
*
Expand All @@ -30,6 +30,11 @@ import kotlin.coroutines.*
* suspend fun <T> BlockingQueue<T>.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 <T> runInterruptible(
context: CoroutineContext = EmptyCoroutineContext,
Expand Down

0 comments on commit 8f40921

Please sign in to comment.