Skip to content

Commit 259000f

Browse files
authored
Adopt AutoCloseable from standard library for CloseableCoroutineDispa… (#4123)
* Adopt AutoCloseable from the standard library for CloseableCoroutineDispatcher * It's stable in 2.0 * For JVM, use Java's AutoCloseable as on Kotlin 1.9.x there is no JVM counterpart
1 parent c9c735a commit 259000f

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

kotlinx-coroutines-core/api/kotlinx-coroutines-core.api

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public final class kotlinx/coroutines/ExceptionsKt {
346346
public static final fun CancellationException (Ljava/lang/String;Ljava/lang/Throwable;)Ljava/util/concurrent/CancellationException;
347347
}
348348

349-
public abstract class kotlinx/coroutines/ExecutorCoroutineDispatcher : kotlinx/coroutines/CoroutineDispatcher, java/io/Closeable {
349+
public abstract class kotlinx/coroutines/ExecutorCoroutineDispatcher : kotlinx/coroutines/CoroutineDispatcher, java/io/Closeable, java/lang/AutoCloseable {
350350
public static final field Key Lkotlinx/coroutines/ExecutorCoroutineDispatcher$Key;
351351
public fun <init> ()V
352352
public abstract fun close ()V

kotlinx-coroutines-core/api/kotlinx-coroutines-core.klib.api

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class <#A: kotlin/Any?> kotlinx.coroutines.flow/AbstractFlow : kotlinx.
4545
constructor <init>() // kotlinx.coroutines.flow/AbstractFlow.<init>|<init>(){}[0]
4646
final suspend fun collect(kotlinx.coroutines.flow/FlowCollector<#A>) // kotlinx.coroutines.flow/AbstractFlow.collect|collect(kotlinx.coroutines.flow.FlowCollector<1:0>){}[0]
4747
}
48-
abstract class kotlinx.coroutines/CloseableCoroutineDispatcher : kotlinx.coroutines/CoroutineDispatcher { // kotlinx.coroutines/CloseableCoroutineDispatcher|null[0]
48+
abstract class kotlinx.coroutines/CloseableCoroutineDispatcher : kotlin/AutoCloseable, kotlinx.coroutines/CoroutineDispatcher { // kotlinx.coroutines/CloseableCoroutineDispatcher|null[0]
4949
abstract fun close() // kotlinx.coroutines/CloseableCoroutineDispatcher.close|close(){}[0]
5050
constructor <init>() // kotlinx.coroutines/CloseableCoroutineDispatcher.<init>|<init>(){}[0]
5151
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ package kotlinx.coroutines
1111
* might be added to this interface in the future, but is stable for use.
1212
*/
1313
@ExperimentalCoroutinesApi
14-
public expect abstract class CloseableCoroutineDispatcher() : CoroutineDispatcher {
14+
public expect abstract class CloseableCoroutineDispatcher() : CoroutineDispatcher, AutoCloseable {
1515

1616
/**
1717
* Initiate the closing sequence of the coroutine dispatcher.
@@ -20,5 +20,5 @@ public expect abstract class CloseableCoroutineDispatcher() : CoroutineDispatche
2020
*
2121
* Invocations of `close` are idempotent and thread-safe.
2222
*/
23-
public abstract fun close()
23+
public abstract override fun close()
2424
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package kotlinx.coroutines
22

3-
public actual abstract class CloseableCoroutineDispatcher actual constructor() : CoroutineDispatcher() {
4-
public actual abstract fun close()
3+
public actual abstract class CloseableCoroutineDispatcher actual constructor() : CoroutineDispatcher(), AutoCloseable {
4+
public actual abstract override fun close()
55
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package kotlinx.coroutines
22

33
import kotlinx.coroutines.flow.*
44
import kotlinx.coroutines.internal.*
5-
import java.io.*
5+
import java.io.Closeable
66
import java.util.concurrent.*
77
import kotlin.coroutines.*
8+
import kotlin.AutoCloseable
89

910
/**
1011
* [CoroutineDispatcher] that has underlying [Executor] for dispatching tasks.
@@ -13,7 +14,7 @@ import kotlin.coroutines.*
1314
* This class is generally used as a bridge between coroutine-based API and
1415
* asynchronous API that requires an instance of the [Executor].
1516
*/
16-
public abstract class ExecutorCoroutineDispatcher: CoroutineDispatcher(), Closeable {
17+
public abstract class ExecutorCoroutineDispatcher : CoroutineDispatcher(), Closeable, AutoCloseable {
1718
/** @suppress */
1819
@ExperimentalStdlibApi
1920
public companion object Key : AbstractCoroutineContextKey<CoroutineDispatcher, ExecutorCoroutineDispatcher>(
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package kotlinx.coroutines
22

3-
public actual abstract class CloseableCoroutineDispatcher actual constructor() : CoroutineDispatcher() {
4-
public actual abstract fun close()
3+
public actual abstract class CloseableCoroutineDispatcher actual constructor() : CoroutineDispatcher(), AutoCloseable {
4+
public actual abstract override fun close()
55
}

0 commit comments

Comments
 (0)