Skip to content

Commit 0358568

Browse files
committed
shutdown() method moved to common Dispatchers
1 parent e51fd5c commit 0358568

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,14 @@ public expect object Dispatchers {
7878
* the value of [CoroutineStart.UNDISPATCHED].
7979
*/
8080
public val Unconfined: CoroutineDispatcher
81+
82+
/**
83+
* Shuts down the dispatcher.
84+
*
85+
* Its implementation depends on the platform:
86+
* - On Kotlin/JVM and Kotlin/JS takes no effect.
87+
* - On Kotlin/Native requests termination of the worker created by the [Default] dispatcher.
88+
*/
89+
@ExperimentalCoroutinesApi
90+
public fun CoroutineDispatcher.shutdown()
8191
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public actual object Dispatchers {
1010
public actual val Default: CoroutineDispatcher = createDefaultDispatcher()
1111
public actual val Main: MainCoroutineDispatcher = JsMainDispatcher(Default, false)
1212
public actual val Unconfined: CoroutineDispatcher = kotlinx.coroutines.Unconfined
13+
public actual fun CoroutineDispatcher.shutdown() {}
1314
}
1415

1516
private class JsMainDispatcher(

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

+2
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,6 @@ public actual object Dispatchers {
115115
*/
116116
@JvmStatic
117117
public val IO: CoroutineDispatcher = DefaultScheduler.IO
118+
119+
public actual fun CoroutineDispatcher.shutdown() {}
118120
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ public actual object Dispatchers {
1313
public actual val Main: MainCoroutineDispatcher = createMainDispatcher(Default)
1414
public actual val Unconfined: CoroutineDispatcher get() = kotlinx.coroutines.Unconfined // Avoid freezing
1515

16-
@ExperimentalCoroutinesApi
17-
public fun CoroutineDispatcher.shutdown() {
16+
public actual fun CoroutineDispatcher.shutdown() {
1817
if (this === DefaultDispatcher) shutdown()
1918
}
2019
}

0 commit comments

Comments
 (0)