Skip to content

Commit c4c592b

Browse files
authored
Deprecate abstract coroutine context keys (#4522)
Additionally, removed the outdated opt-ins into experimental standard library APIs, as those are all stable now. Fixes #4333
1 parent 5471a44 commit c4c592b

File tree

11 files changed

+14
-17
lines changed

11 files changed

+14
-17
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public abstract class CoroutineDispatcher :
6161
AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
6262

6363
/** @suppress */
64+
@Deprecated("Use ContinuationInterceptor.Key and attempt " +
65+
"casting the context element to CoroutineDispatcher instead",
66+
level = DeprecationLevel.WARNING)
67+
// WARNING since 1.11, ERROR since 1.12, remove in 1.13
6468
@ExperimentalStdlibApi
6569
public companion object Key : AbstractCoroutineContextKey<ContinuationInterceptor, CoroutineDispatcher>(
6670
ContinuationInterceptor,

kotlinx-coroutines-core/common/src/flow/SharingStarted.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ private class StartedWhileSubscribed(
185185
.dropWhile { it != SharingCommand.START } // don't emit any STOP/RESET_BUFFER to start with, only START
186186
.distinctUntilChanged() // just in case somebody forgets it, don't leak our multiple sending of START
187187

188-
@OptIn(ExperimentalStdlibApi::class)
189188
override fun toString(): String {
190189
val params = buildList(2) {
191190
if (stopTimeout > 0) add("stopTimeout=${stopTimeout}ms")

kotlinx-coroutines-core/common/src/selects/SelectOld.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,17 @@ internal suspend inline fun <R> selectUnbiasedOld(crossinline builder: SelectBui
122122
scope.initSelectResult()
123123
}
124124

125-
@OptIn(ExperimentalStdlibApi::class)
126125
private fun <T> CancellableContinuation<T>.resumeUndispatched(result: T) {
127-
val dispatcher = context[CoroutineDispatcher]
126+
val dispatcher = context[ContinuationInterceptor] as? CoroutineDispatcher
128127
if (dispatcher != null) {
129128
dispatcher.resumeUndispatched(result)
130129
} else {
131130
resume(result)
132131
}
133132
}
134133

135-
@OptIn(ExperimentalStdlibApi::class)
136134
private fun CancellableContinuation<*>.resumeUndispatchedWithException(exception: Throwable) {
137-
val dispatcher = context[CoroutineDispatcher]
135+
val dispatcher = context[ContinuationInterceptor] as? CoroutineDispatcher
138136
if (dispatcher != null) {
139137
dispatcher.resumeUndispatchedWithException(exception)
140138
} else {

kotlinx-coroutines-core/common/test/flow/sharing/ShareInTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class ShareInTest : TestBase() {
119119
fun testWhileSubscribedCustomAtLeast2() =
120120
testWhileSubscribed(2, SharingStarted.WhileSubscribedAtLeast(2))
121121

122-
@OptIn(ExperimentalStdlibApi::class)
123122
private fun testWhileSubscribed(threshold: Int, started: SharingStarted) = runTest {
124123
expect(1)
125124
val flowState = FlowState()

kotlinx-coroutines-core/common/test/flow/sharing/SharedFlowScenarioTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ class SharedFlowScenarioTest : TestBase() {
267267
private data class ResumeCollecting(val job: TestJob) : Action()
268268
private data class Cancelled(val job: TestJob) : Action()
269269

270-
@OptIn(ExperimentalStdlibApi::class)
271270
private class ScenarioDsl<T>(
272271
val sharedFlow: MutableSharedFlow<T>,
273272
coroutineContext: CoroutineContext

kotlinx-coroutines-core/jvm/src/Executors.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import kotlin.AutoCloseable
1515
*/
1616
public abstract class ExecutorCoroutineDispatcher : CoroutineDispatcher(), Closeable, AutoCloseable {
1717
/** @suppress */
18+
@Deprecated("Use ContinuationInterceptor.Key and attempt " +
19+
"casting the context element to ExecutorCoroutineDispatcher instead",
20+
level = DeprecationLevel.WARNING)
1821
@ExperimentalStdlibApi
22+
@Suppress("DEPRECATION")
1923
public companion object Key : AbstractCoroutineContextKey<CoroutineDispatcher, ExecutorCoroutineDispatcher>(
2024
CoroutineDispatcher,
2125
{ it as? ExecutorCoroutineDispatcher })

kotlinx-coroutines-core/jvm/src/debug/internal/DebugProbesImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ internal object DebugProbesImpl {
176176
* Internal (JVM-public) method used by IDEA debugger as of 1.6.0-RC.
177177
* See KTIJ-24102.
178178
*/
179-
@OptIn(ExperimentalStdlibApi::class)
180179
fun dumpCoroutinesInfoAsJsonAndReferences(): Array<Any> {
181180
val coroutinesInfo = dumpCoroutinesInfo()
182181
val size = coroutinesInfo.size
@@ -186,7 +185,7 @@ internal object DebugProbesImpl {
186185
for (info in coroutinesInfo) {
187186
val context = info.context
188187
val name = context[CoroutineName.Key]?.name?.toStringRepr()
189-
val dispatcher = context[CoroutineDispatcher.Key]?.toStringRepr()
188+
val dispatcher = context[ContinuationInterceptor.Key]?.toStringRepr()
190189
coroutinesInfoAsJson.add(
191190
"""
192191
{

kotlinx-coroutines-core/jvm/test/DispatchersToStringTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
@file:OptIn(ExperimentalStdlibApi::class)
2-
31
package kotlinx.coroutines
42

53
import kotlinx.coroutines.scheduling.CORE_POOL_SIZE
64
import kotlinx.coroutines.scheduling.MAX_POOL_SIZE
5+
import kotlin.coroutines.ContinuationInterceptor
76
import kotlin.test.*
87

98
class DispatchersToStringTest {
@@ -44,7 +43,7 @@ class DispatchersToStringTest {
4443
assertEquals("12", limitedNamed.limitedParallelism(12, "12").toString())
4544

4645
runBlocking {
47-
val d = coroutineContext[CoroutineDispatcher]!!
46+
val d = coroutineContext[ContinuationInterceptor] as CoroutineDispatcher
4847
assertContains(d.toString(), "BlockingEventLoop")
4948
val limited = d.limitedParallelism(2)
5049
assertContains(limited.toString(), "BlockingEventLoop")

kotlinx-coroutines-core/native/src/internal/CoroutineExceptionHandlerImpl.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ internal actual fun ensurePlatformExceptionHandlerLoaded(callback: CoroutineExce
1717
}
1818
}
1919

20-
@OptIn(ExperimentalStdlibApi::class)
2120
internal actual fun propagateExceptionFinalResort(exception: Throwable) {
2221
// log exception
2322
processUnhandledException(exception)

kotlinx-coroutines-core/nativeOther/src/Dispatchers.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ internal actual fun createDefaultDispatcher(): CoroutineDispatcher = DefaultDisp
1010

1111
private object DefaultDispatcher : CoroutineDispatcher() {
1212
// Be consistent with JVM -- at least 2 threads to provide some liveness guarantees in case of improper uses
13-
@OptIn(ExperimentalStdlibApi::class)
1413
private val ctx = newFixedThreadPoolContext(Platform.getAvailableProcessors().coerceAtLeast(2), "Dispatchers.Default")
1514

1615
override fun dispatch(context: CoroutineContext, block: Runnable) {

0 commit comments

Comments
 (0)