Skip to content

Commit

Permalink
Review fixup: signature changed, docs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mvicsokolova committed May 21, 2021
1 parent dce0978 commit ce4a323
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/api/kotlinx-coroutines-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public final class kotlinx/coroutines/Dispatchers {
public static final fun getIO ()Lkotlinx/coroutines/CoroutineDispatcher;
public static final fun getMain ()Lkotlinx/coroutines/MainCoroutineDispatcher;
public static final fun getUnconfined ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun shutdown (Lkotlinx/coroutines/CoroutineDispatcher;)V
public final fun shutdownDefaultDispatcher (Lkotlinx/coroutines/Dispatchers;)V
}

public final class kotlinx/coroutines/DispatchersKt {
Expand Down
14 changes: 11 additions & 3 deletions kotlinx-coroutines-core/common/src/Dispatchers.common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@ public expect object Dispatchers {
public val Unconfined: CoroutineDispatcher

/**
* Shuts down the dispatcher.
* Shuts down the [Default] 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.
* - On Kotlin/Native requests termination of the Worker created by the [Default] dispatcher.
* [Default] dispatcher is backed by a [SingleThreadDispatcher] that creates a Worker and never shuts it down.
* According to the current implementation, Kotlin/Native memory leak checker can not do it’s job while
* there are active workers left at the program shutdown. Thus, if the memory leak checker is activated
* (`Platform.isMemoryLeakCheckerActive = true`) this method should be called before program termination
* to avoid the leaking worker.
*
* **Note**: For now this declaration is only present in `native-mt` versions of `kotlinx.coroutines`.
* It will be available in regular versions when #2558 is implemeted.
*/
@ExperimentalCoroutinesApi
public fun CoroutineDispatcher.shutdown()
public fun Dispatchers.shutdownDefaultDispatcher()
}
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/js/src/Dispatchers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +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() {}
public actual fun Dispatchers.shutdownDefaultDispatcher() {}
}

private class JsMainDispatcher(
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/jvm/src/Dispatchers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,5 @@ public actual object Dispatchers {
@JvmStatic
public val IO: CoroutineDispatcher = DefaultScheduler.IO

public actual fun CoroutineDispatcher.shutdown() {}
public actual fun Dispatchers.shutdownDefaultDispatcher() {}
}
4 changes: 2 additions & 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,8 @@ public actual object Dispatchers {
public actual val Main: MainCoroutineDispatcher = createMainDispatcher(Default)
public actual val Unconfined: CoroutineDispatcher get() = kotlinx.coroutines.Unconfined // Avoid freezing

public actual fun CoroutineDispatcher.shutdown() {
if (this === DefaultDispatcher) shutdown()
public actual fun Dispatchers.shutdownDefaultDispatcher() {
DefaultDispatcher.shutdown()
}
}

Expand Down

0 comments on commit ce4a323

Please sign in to comment.