Skip to content

Commit

Permalink
shutdown() method moved to common Dispatchers
Browse files Browse the repository at this point in the history
  • Loading branch information
mvicsokolova committed Apr 19, 2021
1 parent e51fd5c commit 0358568
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions kotlinx-coroutines-core/common/src/Dispatchers.common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,14 @@ public expect object Dispatchers {
* the value of [CoroutineStart.UNDISPATCHED].
*/
public val Unconfined: CoroutineDispatcher

/**
* Shuts down the dispatcher.
*
* Its implementation depends on the platform:
* - On Kotlin/JVM and Kotlin/JS takes no effect.
* - On Kotlin/Native requests termination of the worker created by the [Default] dispatcher.
*/
@ExperimentalCoroutinesApi
public fun CoroutineDispatcher.shutdown()
}
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/js/src/Dispatchers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public actual object Dispatchers {
public actual val Default: CoroutineDispatcher = createDefaultDispatcher()
public actual val Main: MainCoroutineDispatcher = JsMainDispatcher(Default, false)
public actual val Unconfined: CoroutineDispatcher = kotlinx.coroutines.Unconfined
public actual fun CoroutineDispatcher.shutdown() {}
}

private class JsMainDispatcher(
Expand Down
2 changes: 2 additions & 0 deletions kotlinx-coroutines-core/jvm/src/Dispatchers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ public actual object Dispatchers {
*/
@JvmStatic
public val IO: CoroutineDispatcher = DefaultScheduler.IO

public actual fun CoroutineDispatcher.shutdown() {}
}
3 changes: 1 addition & 2 deletions kotlinx-coroutines-core/native/src/Dispatchers.native.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public actual object Dispatchers {
public actual val Main: MainCoroutineDispatcher = createMainDispatcher(Default)
public actual val Unconfined: CoroutineDispatcher get() = kotlinx.coroutines.Unconfined // Avoid freezing

@ExperimentalCoroutinesApi
public fun CoroutineDispatcher.shutdown() {
public actual fun CoroutineDispatcher.shutdown() {
if (this === DefaultDispatcher) shutdown()
}
}
Expand Down

0 comments on commit 0358568

Please sign in to comment.