Skip to content

Explicitly describe undispatched behaviour in runInterruptible #3139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion kotlinx-coroutines-core/jvm/src/Interruptible.kt
Original file line number Diff line number Diff line change
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