Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce CloseableCoroutineDispatcher abstract class (#2903)
* Introduce CloseableCoroutineDispatcher abstract class * Alias it to ExecutorCoroutineDispatcher on JVM as the most appropriate candidate * Add abstract classes to JVM and Native * This class will be implemented by new dispatchers for K/N new memory model Co-authored-by: dkhalanskyjb <52952525+dkhalanskyjb@users.noreply.github.com>
- Loading branch information
1 parent
12d70eb
commit 7523368
Showing
5 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
kotlinx-coroutines-core/common/src/CloseableCoroutineDispatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines | ||
|
||
/** | ||
* [CoroutineDispatcher] that provides a method to close it, | ||
* causing the rejection of any new tasks and cleanup of all underlying resources | ||
* associated with the current dispatcher. | ||
* Examples of closeable dispatchers are dispatchers backed by `java.lang.Executor` and | ||
* by `kotlin.native.Worker`. | ||
* | ||
* **The `CloseableCoroutineDispatcher` class is not stable for inheritance in 3rd party libraries**, as new methods | ||
* might be added to this interface in the future, but is stable for use. | ||
*/ | ||
@ExperimentalCoroutinesApi | ||
public expect abstract class CloseableCoroutineDispatcher() : CoroutineDispatcher { | ||
|
||
/** | ||
* Initiate the closing sequence of the coroutine dispatcher. | ||
* After a successful call to [close], no new tasks will | ||
* be accepted to be [dispatched][dispatch], but the previously dispatched tasks will be run. | ||
* | ||
* Invocations of `close` are idempotent and thread-safe. | ||
*/ | ||
public abstract fun close() | ||
} |
9 changes: 9 additions & 0 deletions
9
kotlinx-coroutines-core/js/src/CloseableCoroutineDispatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines | ||
|
||
public actual abstract class CloseableCoroutineDispatcher actual constructor() : CoroutineDispatcher() { | ||
public actual abstract fun close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
kotlinx-coroutines-core/native/src/CloseableCoroutineDispatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines | ||
|
||
public actual abstract class CloseableCoroutineDispatcher actual constructor() : CoroutineDispatcher() { | ||
public actual abstract fun close() | ||
} |