Skip to content

Commit e16eb9d

Browse files
authored
Update experimental declarations (#2316)
* Gracefully increase deprecation level on Channel operators instead of removing them, a warning was not strict enough * Remove hidden onCompletion from -M release * Promote StateFlow and SharedFlow to stable API * Lift out experimentality where it is applicable * CoroutineDispatcher.invoke * ReceiveChannel.consume and ReceiveChannel.consumeEach * Flow core operators: onStart, onCompletion, onEmpty * CompletableDeferred.completeWith * awaitCancellation * Add experimentality notes where applicable
1 parent 92db4e1 commit e16eb9d

File tree

23 files changed

+222
-1669
lines changed

23 files changed

+222
-1669
lines changed

benchmarks/src/jmh/kotlin/benchmarks/ChannelSinkBenchmark.kt

+18
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,22 @@ open class ChannelSinkBenchmark {
5050
for (i in start until (start + count))
5151
send(i)
5252
}
53+
54+
// Migrated from deprecated operators, are good only for stressing channels
55+
56+
private fun <E> ReceiveChannel<E>.filter(context: CoroutineContext = Dispatchers.Unconfined, predicate: suspend (E) -> Boolean): ReceiveChannel<E> =
57+
GlobalScope.produce(context, onCompletion = { cancel() }) {
58+
for (e in this@filter) {
59+
if (predicate(e)) send(e)
60+
}
61+
}
62+
63+
private suspend inline fun <E, R> ReceiveChannel<E>.fold(initial: R, operation: (acc: R, E) -> R): R {
64+
var accumulator = initial
65+
consumeEach {
66+
accumulator = operation(accumulator, it)
67+
}
68+
return accumulator
69+
}
5370
}
71+

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

-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,6 @@ public final class kotlinx/coroutines/flow/FlowKt {
992992
public static final fun merge (Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow;
993993
public static final fun merge ([Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow;
994994
public static final fun observeOn (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/flow/Flow;
995-
public static final synthetic fun onCompletion (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow;
996995
public static final fun onCompletion (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function3;)Lkotlinx/coroutines/flow/Flow;
997996
public static final fun onEach (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow;
998997
public static final fun onEmpty (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow;

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

-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ public suspend fun <T> withContext(
175175
*
176176
* This inline function calls [withContext].
177177
*/
178-
@ExperimentalCoroutinesApi
179178
public suspend inline operator fun <T> CoroutineDispatcher.invoke(
180179
noinline block: suspend CoroutineScope.() -> T
181180
): T = withContext(this, block)

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

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public interface CompletableDeferred<T> : Deferred<T> {
5757
* This function transitions this deferred in the same ways described by [CompletableDeferred.complete] and
5858
* [CompletableDeferred.completeExceptionally].
5959
*/
60-
@ExperimentalCoroutinesApi // since 1.3.2, tentatively until 1.4.0
6160
public fun <T> CompletableDeferred<T>.completeWith(result: Result<T>): Boolean =
6261
result.fold({ complete(it) }, { completeExceptionally(it) })
6362

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public enum class CoroutineStart {
5555
* Cancellability of coroutine at suspension points depends on the particular implementation details of
5656
* suspending functions as in [DEFAULT].
5757
*/
58-
@ExperimentalCoroutinesApi
58+
@ExperimentalCoroutinesApi // Since 1.0.0, no ETA on stability
5959
ATOMIC,
6060

6161
/**
@@ -71,7 +71,7 @@ public enum class CoroutineStart {
7171
*
7272
* **Note: This is an experimental api.** Execution semantics of coroutines may change in the future when this mode is used.
7373
*/
74-
@ExperimentalCoroutinesApi
74+
@ExperimentalCoroutinesApi // Since 1.0.0, no ETA on stability
7575
UNDISPATCHED;
7676

7777
/**

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal expect fun assert(value: () -> Boolean)
2727
* Copy mechanism is used only on JVM, but it might be convenient to implement it in common exceptions,
2828
* so on JVM their stacktraces will be properly recovered.
2929
*/
30-
@ExperimentalCoroutinesApi
30+
@ExperimentalCoroutinesApi // Since 1.2.0, no ETA on stability
3131
public interface CopyableThrowable<T> where T : Throwable, T : CopyableThrowable<T> {
3232

3333
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public interface Delay {
9595
* }
9696
* ```
9797
*/
98-
@ExperimentalCoroutinesApi
9998
public suspend fun awaitCancellation(): Nothing = suspendCancellableCoroutine {}
10099

101100
/**

kotlinx-coroutines-core/common/src/channels/Broadcast.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public fun <E> ReceiveChannel<E>.broadcast(
4747
val scope = GlobalScope + Dispatchers.Unconfined + CoroutineExceptionHandler { _, _ -> }
4848
// We can run this coroutine in the context that ignores all exceptions, because of `onCompletion = consume()`
4949
// which passes all exceptions upstream to the source ReceiveChannel
50-
return scope.broadcast(capacity = capacity, start = start, onCompletion = consumes()) {
50+
return scope.broadcast(capacity = capacity, start = start, onCompletion = { cancelConsumed(it) }) {
5151
for (e in this@broadcast) {
5252
send(e)
5353
}

kotlinx-coroutines-core/common/src/channels/BufferOverflow.kt

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import kotlinx.coroutines.*
1616
* * [DROP_LATEST] &mdash; drop **the latest** value that is being added to the buffer right now on buffer overflow
1717
* (so that buffer contents stay the same), do not suspend.
1818
*/
19-
@ExperimentalCoroutinesApi
2019
public enum class BufferOverflow {
2120
/**
2221
* Suspend on buffer overflow.

0 commit comments

Comments
 (0)