diff --git a/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api b/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api index 546bfe3507..9ccef08308 100644 --- a/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api +++ b/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api @@ -889,8 +889,6 @@ public final class kotlinx/coroutines/flow/FlowKt { public static final fun asFlow ([Ljava/lang/Object;)Lkotlinx/coroutines/flow/Flow; public static final fun asSharedFlow (Lkotlinx/coroutines/flow/MutableSharedFlow;)Lkotlinx/coroutines/flow/SharedFlow; public static final fun asStateFlow (Lkotlinx/coroutines/flow/MutableStateFlow;)Lkotlinx/coroutines/flow/StateFlow; - public static final fun broadcastIn (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/coroutines/CoroutineStart;)Lkotlinx/coroutines/channels/BroadcastChannel; - public static synthetic fun broadcastIn$default (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/coroutines/CoroutineStart;ILjava/lang/Object;)Lkotlinx/coroutines/channels/BroadcastChannel; public static final synthetic fun buffer (Lkotlinx/coroutines/flow/Flow;I)Lkotlinx/coroutines/flow/Flow; public static final fun buffer (Lkotlinx/coroutines/flow/Flow;ILkotlinx/coroutines/channels/BufferOverflow;)Lkotlinx/coroutines/flow/Flow; public static synthetic fun buffer$default (Lkotlinx/coroutines/flow/Flow;IILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow; @@ -961,10 +959,6 @@ public final class kotlinx/coroutines/flow/FlowKt { public static final fun flowOf (Ljava/lang/Object;)Lkotlinx/coroutines/flow/Flow; public static final fun flowOf ([Ljava/lang/Object;)Lkotlinx/coroutines/flow/Flow; public static final fun flowOn (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/flow/Flow; - public static final fun flowViaChannel (ILkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow; - public static synthetic fun flowViaChannel$default (ILkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow; - public static final fun flowWith (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;ILkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/flow/Flow; - public static synthetic fun flowWith$default (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;ILkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow; public static final fun fold (Lkotlinx/coroutines/flow/Flow;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun forEach (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;)V public static final fun getDEFAULT_CONCURRENCY ()I @@ -981,8 +975,6 @@ public final class kotlinx/coroutines/flow/FlowKt { public static final fun onCompletion (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function3;)Lkotlinx/coroutines/flow/Flow; public static final fun onEach (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow; public static final fun onEmpty (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow; - public static final fun onErrorCollect (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/flow/Flow; - public static synthetic fun onErrorCollect$default (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow; public static final fun onErrorResume (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow; public static final fun onErrorResumeNext (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow; public static final fun onErrorReturn (Lkotlinx/coroutines/flow/Flow;Ljava/lang/Object;)Lkotlinx/coroutines/flow/Flow; @@ -998,9 +990,7 @@ public final class kotlinx/coroutines/flow/FlowKt { public static final fun reduce (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun replay (Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow; public static final fun replay (Lkotlinx/coroutines/flow/Flow;I)Lkotlinx/coroutines/flow/Flow; - public static final synthetic fun retry (Lkotlinx/coroutines/flow/Flow;ILkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/flow/Flow; public static final fun retry (Lkotlinx/coroutines/flow/Flow;JLkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow; - public static synthetic fun retry$default (Lkotlinx/coroutines/flow/Flow;ILkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow; public static synthetic fun retry$default (Lkotlinx/coroutines/flow/Flow;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow; public static final fun retryWhen (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function4;)Lkotlinx/coroutines/flow/Flow; public static final fun runningFold (Lkotlinx/coroutines/flow/Flow;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;)Lkotlinx/coroutines/flow/Flow; diff --git a/kotlinx-coroutines-core/common/README.md b/kotlinx-coroutines-core/common/README.md index b00921bbcd..b09c44c75e 100644 --- a/kotlinx-coroutines-core/common/README.md +++ b/kotlinx-coroutines-core/common/README.md @@ -66,10 +66,6 @@ This module provides debugging facilities for coroutines (run JVM with `-ea` or and [newCoroutineContext] function to write user-defined coroutine builders that work with these debugging facilities. See [DEBUG_PROPERTY_NAME] for more details. -This module provides a special CoroutineContext type [TestCoroutineCoroutineContext][kotlinx.coroutines.test.TestCoroutineContext] that -allows the writer of code that contains Coroutines with delays and timeouts to write non-flaky unit-tests for that code allowing these tests to -terminate in near zero time. See the documentation for this class for more information. - # Package kotlinx.coroutines General-purpose coroutine builders, contexts, and helper functions. @@ -130,7 +126,6 @@ Low-level primitives for finer-grained control of coroutines. [kotlinx.coroutines.sync.Mutex]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html [kotlinx.coroutines.sync.Mutex.lock]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/lock.html -[kotlinx.coroutines.sync.Mutex.tryLock]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/try-lock.html @@ -155,8 +150,4 @@ Low-level primitives for finer-grained control of coroutines. [kotlinx.coroutines.selects.select]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.selects/select.html [kotlinx.coroutines.selects.SelectBuilder.onTimeout]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.selects/on-timeout.html - - -[kotlinx.coroutines.test.TestCoroutineContext]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.test/-test-coroutine-context/index.html - diff --git a/kotlinx-coroutines-core/common/src/channels/AbstractChannel.kt b/kotlinx-coroutines-core/common/src/channels/AbstractChannel.kt index 4751296c87..b92ced6ab7 100644 --- a/kotlinx-coroutines-core/common/src/channels/AbstractChannel.kt +++ b/kotlinx-coroutines-core/common/src/channels/AbstractChannel.kt @@ -136,7 +136,7 @@ internal abstract class AbstractSendChannel( return sendSuspend(element) } - @Suppress("DEPRECATION") + @Suppress("DEPRECATION", "DEPRECATION_ERROR") override fun offer(element: E): Boolean { // Temporary migration for offer users who rely on onUndeliveredElement try { diff --git a/kotlinx-coroutines-core/common/src/channels/Channel.kt b/kotlinx-coroutines-core/common/src/channels/Channel.kt index b24658a4c4..68ed5f1e78 100644 --- a/kotlinx-coroutines-core/common/src/channels/Channel.kt +++ b/kotlinx-coroutines-core/common/src/channels/Channel.kt @@ -157,10 +157,10 @@ public interface SendChannel { * @suppress **Deprecated**. */ @Deprecated( - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, message = "Deprecated in the favour of 'trySend' method", replaceWith = ReplaceWith("trySend(element).isSuccess") - ) // Warning since 1.5.0 + ) // Warning since 1.5.0, error since 1.6.0 public fun offer(element: E): Boolean { val result = trySend(element) if (result.isSuccess) return true @@ -313,12 +313,12 @@ public interface ReceiveChannel { * @suppress **Deprecated**. */ @Deprecated( - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, message = "Deprecated in the favour of 'tryReceive'. " + "Please note that the provided replacement does not rethrow channel's close cause as 'poll' did, " + "for the precise replacement please refer to the 'poll' documentation", replaceWith = ReplaceWith("tryReceive().getOrNull()") - ) // Warning since 1.5.0 + ) // Warning since 1.5.0, error since 1.6.0 public fun poll(): E? { val result = tryReceive() if (result.isSuccess) return result.getOrThrow() @@ -364,7 +364,7 @@ public interface ReceiveChannel { message = "Deprecated in favor of onReceiveCatching extension", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("onReceiveCatching") - ) // Warning since 1.3.0, error in 1.5.0, will be hidden or removed in 1.6.0 + ) // Warning since 1.3.0, error in 1.5.0, will be hidden or removed in 1.7.0 public val onReceiveOrNull: SelectClause1 get() { return object : SelectClause1 { diff --git a/kotlinx-coroutines-core/common/src/channels/Channels.common.kt b/kotlinx-coroutines-core/common/src/channels/Channels.common.kt index e0b4f9d2a5..a78e2f186d 100644 --- a/kotlinx-coroutines-core/common/src/channels/Channels.common.kt +++ b/kotlinx-coroutines-core/common/src/channels/Channels.common.kt @@ -50,7 +50,7 @@ public inline fun BroadcastChannel.consume(block: ReceiveChannel.() @Deprecated( "Deprecated in the favour of 'receiveCatching'", ReplaceWith("receiveCatching().getOrNull()"), - DeprecationLevel.WARNING + DeprecationLevel.ERROR ) // Warning since 1.5.0, ERROR in 1.6.0, HIDDEN in 1.7.0 @Suppress("EXTENSION_SHADOWED_BY_MEMBER") public suspend fun ReceiveChannel.receiveOrNull(): E? { @@ -63,7 +63,7 @@ public suspend fun ReceiveChannel.receiveOrNull(): E? { */ @Deprecated( "Deprecated in the favour of 'onReceiveCatching'", - level = DeprecationLevel.WARNING + level = DeprecationLevel.ERROR ) // Warning since 1.5.0, ERROR in 1.6.0, HIDDEN in 1.7.0 public fun ReceiveChannel.onReceiveOrNull(): SelectClause1 { @Suppress("DEPRECATION", "UNCHECKED_CAST") diff --git a/kotlinx-coroutines-core/common/src/flow/Builders.kt b/kotlinx-coroutines-core/common/src/flow/Builders.kt index 66b55a90c0..c4b55e104b 100644 --- a/kotlinx-coroutines-core/common/src/flow/Builders.kt +++ b/kotlinx-coroutines-core/common/src/flow/Builders.kt @@ -198,25 +198,6 @@ public fun LongRange.asFlow(): Flow = flow { } } -/** - * @suppress - */ -@FlowPreview -@Deprecated( - message = "Use channelFlow with awaitClose { } instead of flowViaChannel and invokeOnClose { }.", - level = DeprecationLevel.ERROR -) // To be removed in 1.4.x -@Suppress("DeprecatedCallableAddReplaceWith") -public fun flowViaChannel( - bufferSize: Int = BUFFERED, - @BuilderInference block: CoroutineScope.(channel: SendChannel) -> Unit -): Flow { - return channelFlow { - block(channel) - awaitClose() - }.buffer(bufferSize) -} - /** * Creates an instance of a _cold_ [Flow] with elements that are sent to a [SendChannel] * provided to the builder's [block] of code via [ProducerScope]. It allows elements to be diff --git a/kotlinx-coroutines-core/common/src/flow/Channels.kt b/kotlinx-coroutines-core/common/src/flow/Channels.kt index 382953efcb..82dd8d5cdf 100644 --- a/kotlinx-coroutines-core/common/src/flow/Channels.kt +++ b/kotlinx-coroutines-core/common/src/flow/Channels.kt @@ -178,41 +178,6 @@ public fun BroadcastChannel.asFlow(): Flow = flow { emitAll(openSubscription()) } -/** - * ### Deprecated - * - * **This API is deprecated.** The [BroadcastChannel] provides a complex channel-like API for hot flows. - * [SharedFlow] is an easier-to-use and more flow-centric API for the same purposes, so using - * [shareIn] operator is preferred. It is not a direct replacement, so please - * study [shareIn] documentation to see what kind of shared flow fits your use-case. As a rule of thumb: - * - * * Replace `broadcastIn(scope)` and `broadcastIn(scope, CoroutineStart.LAZY)` with `shareIn(scope, 0, SharingStarted.Lazily)`. - * * Replace `broadcastIn(scope, CoroutineStart.DEFAULT)` with `shareIn(scope, 0, SharingStarted.Eagerly)`. - */ -@Deprecated( - message = "Use shareIn operator and the resulting SharedFlow as a replacement for BroadcastChannel", - replaceWith = ReplaceWith("this.shareIn(scope, SharingStarted.Lazily, 0)"), - level = DeprecationLevel.ERROR -) // WARNING in 1.4.0, error in 1.5.0, removed in 1.6.0 (was @FlowPreview) -public fun Flow.broadcastIn( - scope: CoroutineScope, - start: CoroutineStart = CoroutineStart.LAZY -): BroadcastChannel { - // Backwards compatibility with operator fusing - val channelFlow = asChannelFlow() - val capacity = when (channelFlow.onBufferOverflow) { - BufferOverflow.SUSPEND -> channelFlow.produceCapacity - BufferOverflow.DROP_OLDEST -> Channel.CONFLATED - BufferOverflow.DROP_LATEST -> - throw IllegalArgumentException("Broadcast channel does not support BufferOverflow.DROP_LATEST") - } - return scope.broadcast(channelFlow.context, capacity = capacity, start = start) { - collect { value -> - send(value) - } - } -} - /** * Creates a [produce] coroutine that collects the given flow. * diff --git a/kotlinx-coroutines-core/common/src/flow/operators/Context.kt b/kotlinx-coroutines-core/common/src/flow/operators/Context.kt index 04342ed074..ace01e1d44 100644 --- a/kotlinx-coroutines-core/common/src/flow/operators/Context.kt +++ b/kotlinx-coroutines-core/common/src/flow/operators/Context.kt @@ -277,64 +277,6 @@ private class CancellableFlowImpl(private val flow: Flow) : CancellableFlo } } -/** - * The operator that changes the context where all transformations applied to the given flow within a [builder] are executed. - * This operator is context preserving and does not affect the context of the preceding and subsequent operations. - * - * Example: - * - * ``` - * flow // not affected - * .map { ... } // Not affected - * .flowWith(Dispatchers.IO) { - * map { ... } // in IO - * .filter { ... } // in IO - * } - * .map { ... } // Not affected - * ``` - * - * For more explanation of context preservation please refer to [Flow] documentation. - * - * This operator is deprecated without replacement because it was discovered that it doesn't play well with coroutines - * and flow semantics: - * - * 1) It doesn't prevent context elements from the downstream to leak into its body - * ``` - * flowOf(1).flowWith(EmptyCoroutineContext) { - * onEach { println(kotlin.coroutines.coroutineContext[CoroutineName]) } // Will print 42 - * }.flowOn(CoroutineName(42)) - * ``` - * 2) To avoid such leaks, new primitive should be introduced to `kotlinx.coroutines` -- the subtraction of contexts. - * And this will become a new concept to learn, maintain and explain. - * 3) It defers the execution of declarative [builder] until the moment of [collection][Flow.collect] similarly - * to `Observable.defer`. But it is unexpected because nothing in the name `flowWith` reflects this fact. - * 4) It can be confused with [flowOn] operator, though [flowWith] is much rarer. - * - * @suppress - */ -@FlowPreview -@Deprecated(message = "flowWith is deprecated without replacement, please refer to its KDoc for an explanation", level = DeprecationLevel.ERROR) // Error in beta release, removal in 1.4 -public fun Flow.flowWith( - flowContext: CoroutineContext, - bufferSize: Int = BUFFERED, - builder: Flow.() -> Flow -): Flow { - checkFlowContext(flowContext) - val source = this - return unsafeFlow { - /** - * Here we should remove a Job instance from the context. - * All builders are written using scoping and no global coroutines are launched, so it is safe not to provide explicit Job. - * It is also necessary not to mess with cancellation if multiple flowWith are used. - */ - val originalContext = currentCoroutineContext().minusKey(Job) - val prepared = source.flowOn(originalContext).buffer(bufferSize) - builder(prepared).flowOn(flowContext).buffer(bufferSize).collect { value -> - return@collect emit(value) - } - } -} - private fun checkFlowContext(context: CoroutineContext) { require(context[Job] == null) { "Flow context cannot contain job in it. Had $context" diff --git a/kotlinx-coroutines-core/common/src/flow/operators/Errors.kt b/kotlinx-coroutines-core/common/src/flow/operators/Errors.kt index c406c8bd72..30512f407d 100644 --- a/kotlinx-coroutines-core/common/src/flow/operators/Errors.kt +++ b/kotlinx-coroutines-core/common/src/flow/operators/Errors.kt @@ -60,35 +60,6 @@ public fun Flow.catch(action: suspend FlowCollector.(cause: Throwable) if (exception != null) action(exception) } -/** - * @suppress **Deprecated**: Use `(Throwable) -> Boolean` functional type - */ -@Deprecated( - level = DeprecationLevel.ERROR, - message = "Use (Throwable) -> Boolean functional type", - replaceWith = ReplaceWith("(Throwable) -> Boolean") -) -public typealias ExceptionPredicate = (Throwable) -> Boolean - -/** - * Switches to the [fallback] flow if the original flow throws an exception that matches the [predicate]. - * Cancellation exceptions that were caused by the direct [cancel] call are not handled by this operator. - * - * @suppress **Deprecated**: Use `catch { e -> if (predicate(e)) emitAll(fallback) else throw e }` - */ -@Deprecated( - level = DeprecationLevel.ERROR, - message = "Use catch { e -> if (predicate(e)) emitAll(fallback) else throw e }", - replaceWith = ReplaceWith("catch { e -> if (predicate(e)) emitAll(fallback) else throw e }") -) -public fun Flow.onErrorCollect( - fallback: Flow, - predicate: (Throwable) -> Boolean = { true } -): Flow = catch { e -> - if (!predicate(e)) throw e - emitAll(fallback) -} - /** * Retries collection of the given flow up to [retries] times when an exception that matches the * given [predicate] occurs in the upstream flow. This operator is *transparent* to exceptions that occur @@ -124,16 +95,6 @@ public fun Flow.retry( return retryWhen { cause, attempt -> attempt < retries && predicate(cause) } } -@FlowPreview -@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility with retries: Int preview version") -public fun Flow.retry( - retries: Int = Int.MAX_VALUE, - predicate: (Throwable) -> Boolean = { true } -): Flow { - require(retries > 0) { "Expected positive amount of retries, but had $retries" } - return retryWhen { cause, attempt -> predicate(cause) && attempt < retries } -} - /** * Retries collection of the given flow when an exception occurs in the upstream flow and the * [predicate] returns true. The predicate also receives an `attempt` number as parameter, diff --git a/kotlinx-coroutines-core/common/src/sync/Mutex.kt b/kotlinx-coroutines-core/common/src/sync/Mutex.kt index c02422825e..d2a2fcd41b 100644 --- a/kotlinx-coroutines-core/common/src/sync/Mutex.kt +++ b/kotlinx-coroutines-core/common/src/sync/Mutex.kt @@ -65,7 +65,7 @@ public interface Mutex { * Deprecated for removal without built-in replacement. */ @Deprecated(level = DeprecationLevel.WARNING, message = "Mutex.onLock deprecated without replacement. " + - "For additional details please refer to #2794") + "For additional details please refer to #2794") // WARNING since 1.6.0 public val onLock: SelectClause2 /** diff --git a/kotlinx-coroutines-core/jvm/src/channels/Actor.kt b/kotlinx-coroutines-core/jvm/src/channels/Actor.kt index 4657bc7d1e..748f52833f 100644 --- a/kotlinx-coroutines-core/jvm/src/channels/Actor.kt +++ b/kotlinx-coroutines-core/jvm/src/channels/Actor.kt @@ -163,7 +163,7 @@ private class LazyActorCoroutine( return super.send(element) } - @Suppress("DEPRECATION") + @Suppress("DEPRECATION", "DEPRECATION_ERROR") override fun offer(element: E): Boolean { start() return super.offer(element) diff --git a/kotlinx-coroutines-core/jvm/src/channels/Channels.kt b/kotlinx-coroutines-core/jvm/src/channels/Channels.kt index 0df8278b77..d7454027fb 100644 --- a/kotlinx-coroutines-core/jvm/src/channels/Channels.kt +++ b/kotlinx-coroutines-core/jvm/src/channels/Channels.kt @@ -43,11 +43,11 @@ import kotlinx.coroutines.* * ``` */ @Deprecated( - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, message = "Deprecated in the favour of 'trySendBlocking'. " + "Consider handling the result of 'trySendBlocking' explicitly and rethrow exception if necessary", replaceWith = ReplaceWith("trySendBlocking(element)") -) +) // WARNING in 1.5.0, ERROR in 1.6.0, HIDDEN in 1.7.0 public fun SendChannel.sendBlocking(element: E) { // fast path if (trySend(element).isSuccess) diff --git a/kotlinx-coroutines-core/jvm/src/scheduling/Deprecated.kt b/kotlinx-coroutines-core/jvm/src/scheduling/Deprecated.kt index 86b0ade61a..e5defbafcd 100644 --- a/kotlinx-coroutines-core/jvm/src/scheduling/Deprecated.kt +++ b/kotlinx-coroutines-core/jvm/src/scheduling/Deprecated.kt @@ -18,7 +18,7 @@ import kotlin.coroutines.* * To preserve backwards compatibility with Ktor 1.x, previous version of the code is * extracted here as is and isolated from the rest of code base, so R8 can get rid of it. * - * It should be removed after Kotlin 3.0.0 (EOL of Ktor 1.x) around 2022. + * It should be removed after Ktor 3.0.0 (EOL of Ktor 1.x) around 2022. */ @PublishedApi internal open class ExperimentalCoroutineDispatcher( diff --git a/kotlinx-coroutines-core/jvm/src/test_/TestCoroutineContext.kt b/kotlinx-coroutines-core/jvm/src/test_/TestCoroutineContext.kt index 8526ca216a..6a71a4deb4 100644 --- a/kotlinx-coroutines-core/jvm/src/test_/TestCoroutineContext.kt +++ b/kotlinx-coroutines-core/jvm/src/test_/TestCoroutineContext.kt @@ -10,29 +10,10 @@ import kotlinx.coroutines.internal.* import java.util.concurrent.* import kotlin.coroutines.* -/** - * This [CoroutineContext] dispatcher can be used to simulate virtual time to speed up - * code, especially tests, that deal with delays and timeouts in Coroutines. - * - * Provide an instance of this TestCoroutineContext when calling the *non-blocking* - * [launch][CoroutineScope.launch] or [async][CoroutineScope.async] - * and then advance time or trigger the actions to make the co-routines execute as soon as possible. - * - * This works much like the *TestScheduler* in RxJava2, which allows to speed up tests that deal - * with non-blocking Rx chains that contain delays, timeouts, intervals and such. - * - * This dispatcher can also handle *blocking* coroutines that are started by [runBlocking]. - * This dispatcher's virtual time will be automatically advanced based on the delayed actions - * within the Coroutine(s). - * - * **Note: This API will become obsolete in future updates due to integration with structured concurrency.** - * See [issue #541](https://github.com/Kotlin/kotlinx.coroutines/issues/541). - * - * @param name A user-readable name for debugging purposes. - */ +/** @suppress */ @Deprecated("This API has been deprecated to integrate with Structured Concurrency.", ReplaceWith("TestCoroutineScope", "kotlin.coroutines.test"), - level = DeprecationLevel.WARNING) + level = DeprecationLevel.ERROR) // ERROR in 1.6.0, removed in 1.7.0 public class TestCoroutineContext(private val name: String? = null) : CoroutineContext { private val uncaughtExceptions = mutableListOf() @@ -264,28 +245,11 @@ private class TimedRunnableObsolete( override fun toString() = "TimedRunnable(time=$time, run=$run)" } -/** - * Executes a block of code in which a unit-test can be written using the provided [TestCoroutineContext]. The provided - * [TestCoroutineContext] is available in the [testBody] as the `this` receiver. - * - * The [testBody] is executed and an [AssertionError] is thrown if the list of unhandled exceptions is not empty and - * contains any exception that is not a [CancellationException]. - * - * If the [testBody] successfully executes one of the [TestCoroutineContext.assertAllUnhandledExceptions], - * [TestCoroutineContext.assertAnyUnhandledException], [TestCoroutineContext.assertUnhandledException] or - * [TestCoroutineContext.assertExceptions], the list of unhandled exceptions will have been cleared and this method will - * not throw an [AssertionError]. - * - * **Note: This API will become obsolete in future updates due to integration with structured concurrency.** - * See [issue #541](https://github.com/Kotlin/kotlinx.coroutines/issues/541). - * - * @param testContext The provided [TestCoroutineContext]. If not specified, a default [TestCoroutineContext] will be - * provided instead. - * @param testBody The code of the unit-test. - */ +/** @suppress */ @Deprecated("This API has been deprecated to integrate with Structured Concurrency.", ReplaceWith("testContext.runBlockingTest(testBody)", "kotlin.coroutines.test"), - level = DeprecationLevel.WARNING) + level = DeprecationLevel.ERROR) // ERROR in 1.6.0, removed in 1.7.0 +@Suppress("DEPRECATION_ERROR") public fun withTestContext(testContext: TestCoroutineContext = TestCoroutineContext(), testBody: TestCoroutineContext.() -> Unit) { with (testContext) { testBody() diff --git a/kotlinx-coroutines-core/jvm/test/test/TestCoroutineContextTest.kt b/kotlinx-coroutines-core/jvm/test/test/TestCoroutineContextTest.kt deleted file mode 100644 index 4a6f4d24df..0000000000 --- a/kotlinx-coroutines-core/jvm/test/test/TestCoroutineContextTest.kt +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.coroutines.test - -import kotlinx.coroutines.* -import org.junit.* -import org.junit.Test -import kotlin.coroutines.* -import kotlin.test.* - -class TestCoroutineContextTest { - private val injectedContext = TestCoroutineContext() - - @After - fun tearDown() { - injectedContext.cancelAllActions() - } - - @Test - fun testDelayWithLaunch() = withTestContext(injectedContext) { - val delay = 1000L - - var executed = false - launch { - suspendedDelayedAction(delay) { - executed = true - } - } - - advanceTimeBy(delay / 2) - assertFalse(executed) - - advanceTimeBy(delay / 2) - assertTrue(executed) - } - - @Test - fun testTimeJumpWithLaunch() = withTestContext(injectedContext) { - val delay = 1000L - - var executed = false - launch { - suspendedDelayedAction(delay) { - executed = true - } - } - - advanceTimeTo(delay / 2) - assertFalse(executed) - - advanceTimeTo(delay) - assertTrue(executed) - } - - @Test - fun testDelayWithAsync() = withTestContext(injectedContext) { - val delay = 1000L - - var executed = false - async { - suspendedDelayedAction(delay) { - executed = true - } - } - - advanceTimeBy(delay / 2) - assertFalse(executed) - - advanceTimeBy(delay / 2) - assertTrue(executed) - } - - @Test - fun testDelayWithRunBlocking() = withTestContext(injectedContext) { - val delay = 1000L - - var executed = false - runBlocking { - suspendedDelayedAction(delay) { - executed = true - } - } - - assertTrue(executed) - assertEquals(delay, now()) - } - - private suspend fun suspendedDelayedAction(delay: Long, action: () -> Unit) { - delay(delay) - action() - } - - @Test - fun testDelayedFunctionWithRunBlocking() = withTestContext(injectedContext) { - val delay = 1000L - val expectedValue = 16 - - val result = runBlocking { - suspendedDelayedFunction(delay) { - expectedValue - } - } - - assertEquals(expectedValue, result) - assertEquals(delay, now()) - } - - @Test - fun testDelayedFunctionWithAsync() = withTestContext(injectedContext) { - val delay = 1000L - val expectedValue = 16 - - val deferred = async { - suspendedDelayedFunction(delay) { - expectedValue - } - } - - advanceTimeBy(delay / 2) - try { - deferred.getCompleted() - fail("The Job should not have been completed yet.") - } catch (e: Exception) { - // Success. - } - - advanceTimeBy(delay / 2) - assertEquals(expectedValue, deferred.getCompleted()) - } - - private suspend fun TestCoroutineContext.suspendedDelayedFunction(delay: Long, function: () -> T): T { - delay(delay / 4) - return async { - delay((delay / 4) * 3) - function() - }.await() - } - - @Test - fun testBlockingFunctionWithRunBlocking() = withTestContext(injectedContext) { - val delay = 1000L - val expectedValue = 16 - val result = runBlocking { - suspendedBlockingFunction(delay) { - expectedValue - } - } - assertEquals(expectedValue, result) - assertEquals(delay, now()) - } - - @Test - fun testBlockingFunctionWithAsync() = withTestContext(injectedContext) { - val delay = 1000L - val expectedValue = 16 - var now = 0L - val deferred = async { - suspendedBlockingFunction(delay) { - expectedValue - } - } - now += advanceTimeBy((delay / 4) - 1) - assertEquals((delay / 4) - 1, now) - assertEquals(now, now()) - try { - deferred.getCompleted() - fail("The Job should not have been completed yet.") - } catch (e: Exception) { - // Success. - } - now += advanceTimeBy(1) - assertEquals(delay, now()) - assertEquals(now, now()) - assertEquals(expectedValue, deferred.getCompleted()) - } - - private suspend fun TestCoroutineContext.suspendedBlockingFunction(delay: Long, function: () -> T): T { - delay(delay / 4) - return runBlocking { - delay((delay / 4) * 3) - function() - } - } - - @Test - fun testTimingOutFunctionWithAsyncAndNoTimeout() = withTestContext(injectedContext) { - val delay = 1000L - val expectedValue = 67 - - val result = async { - suspendedTimingOutFunction(delay, delay + 1) { - expectedValue - } - } - - triggerActions() - assertEquals(expectedValue, result.getCompleted()) - } - - @Test - fun testTimingOutFunctionWithAsyncAndTimeout() = withTestContext(injectedContext) { - val delay = 1000L - val expectedValue = 67 - - val result = async { - suspendedTimingOutFunction(delay, delay) { - expectedValue - } - } - - triggerActions() - assertTrue(result.getCompletionExceptionOrNull() is TimeoutCancellationException) - } - - @Test - fun testTimingOutFunctionWithRunBlockingAndTimeout() = withTestContext(injectedContext) { - val delay = 1000L - val expectedValue = 67 - - try { - runBlocking { - suspendedTimingOutFunction(delay, delay) { - expectedValue - } - } - fail("Expected TimeoutCancellationException to be thrown.") - } catch (e: TimeoutCancellationException) { - // Success - } catch (e: Throwable) { - fail("Expected TimeoutCancellationException to be thrown: $e") - } - } - - private suspend fun TestCoroutineContext.suspendedTimingOutFunction(delay: Long, timeOut: Long, function: () -> T): T { - return runBlocking { - withTimeout(timeOut) { - delay(delay / 2) - val ret = function() - delay(delay / 2) - ret - } - } - } - - @Test(expected = AssertionError::class) - fun testWithTestContextThrowingAnAssertionError() = withTestContext(injectedContext) { - val expectedError = IllegalAccessError("hello") - - launch { - throw expectedError - } - - triggerActions() - } - - @Test - fun testExceptionHandlingWithLaunch() = withTestContext(injectedContext) { - val expectedError = IllegalAccessError("hello") - - launch { - throw expectedError - } - - triggerActions() - assertUnhandledException { it === expectedError} - } - - @Test - fun testExceptionHandlingWithLaunchingChildCoroutines() = withTestContext(injectedContext) { - val delay = 1000L - val expectedError = TestException("hello") - val expectedValue = 12 - - launch { - suspendedAsyncWithExceptionAfterDelay(delay, expectedError, expectedValue, true) - } - - advanceTimeBy(delay) - assertUnhandledException { it === expectedError} - } - - @Test - fun testExceptionHandlingWithAsyncAndDontWaitForException() = withTestContext(injectedContext) { - val delay = 1000L - val expectedError = IllegalAccessError("hello") - val expectedValue = 12 - - val result = async { - suspendedAsyncWithExceptionAfterDelay(delay, expectedError, expectedValue, false) - } - - advanceTimeBy(delay) - - assertNull(result.getCompletionExceptionOrNull()) - assertEquals(expectedValue, result.getCompleted()) - } - - @Test - fun testExceptionHandlingWithAsyncAndWaitForException() = withTestContext(injectedContext) { - val delay = 1000L - val expectedError = TestException("hello") - val expectedValue = 12 - - val result = async { - suspendedAsyncWithExceptionAfterDelay(delay, expectedError, expectedValue, true) - } - - advanceTimeBy(delay) - - val e = result.getCompletionExceptionOrNull() - assertTrue(expectedError === e, "Expected to be thrown: '$expectedError' but was '$e'") - } - - @Test - fun testExceptionHandlingWithRunBlockingAndDontWaitForException() = withTestContext(injectedContext) { - val delay = 1000L - val expectedError = IllegalAccessError("hello") - val expectedValue = 12 - - val result = runBlocking { - suspendedAsyncWithExceptionAfterDelay(delay, expectedError, expectedValue, false) - } - - advanceTimeBy(delay) - - assertEquals(expectedValue, result) - } - - @Test - fun testExceptionHandlingWithRunBlockingAndWaitForException() = withTestContext(injectedContext) { - val delay = 1000L - val expectedError = TestException("hello") - val expectedValue = 12 - - try { - runBlocking { - suspendedAsyncWithExceptionAfterDelay(delay, expectedError, expectedValue, true) - } - fail("Expected to be thrown: '$expectedError'") - } catch (e: AssertionError) { - throw e - } catch (e: Throwable) { - assertTrue(expectedError === e, "Expected to be thrown: '$expectedError' but was '$e'") - } - } - - private suspend fun TestCoroutineContext.suspendedAsyncWithExceptionAfterDelay(delay: Long, exception: Throwable, value: T, await: Boolean): T { - val deferred = async { - delay(delay - 1) - throw exception - } - - if (await) { - deferred.await() - } - return value - } - - @Test - fun testCancellationException() = withTestContext { - val job = launch { - delay(1000) - } - - advanceTimeBy(500) - job.cancel() - assertAllUnhandledExceptions { it is CancellationException } - } - - @Test - fun testCancellationExceptionNotThrownByWithTestContext() = withTestContext { - val job = launch { - delay(1000) - } - - advanceTimeBy(500) - job.cancel() - } -} - - -/* Some helper functions */ -// todo: deprecate, replace, see https://github.com/Kotlin/kotlinx.coroutines/issues/541 -private fun TestCoroutineContext.launch( - start: CoroutineStart = CoroutineStart.DEFAULT, - parent: Job? = null, - block: suspend CoroutineScope.() -> Unit -) = - GlobalScope.launch(this + (parent ?: EmptyCoroutineContext), start, block) - -// todo: deprecate, replace, see https://github.com/Kotlin/kotlinx.coroutines/issues/541 -private fun TestCoroutineContext.async( - start: CoroutineStart = CoroutineStart.DEFAULT, - parent: Job? = null, - block: suspend CoroutineScope.() -> T - -) = - GlobalScope.async(this + (parent ?: EmptyCoroutineContext), start, block) - -private fun TestCoroutineContext.runBlocking( - block: suspend CoroutineScope.() -> T -) = runBlocking(this, block) diff --git a/reactive/kotlinx-coroutines-reactive/api/kotlinx-coroutines-reactive.api b/reactive/kotlinx-coroutines-reactive/api/kotlinx-coroutines-reactive.api index 75f1b306d3..c82880233a 100644 --- a/reactive/kotlinx-coroutines-reactive/api/kotlinx-coroutines-reactive.api +++ b/reactive/kotlinx-coroutines-reactive/api/kotlinx-coroutines-reactive.api @@ -12,7 +12,7 @@ public final class kotlinx/coroutines/reactive/AwaitKt { public final class kotlinx/coroutines/reactive/ChannelKt { public static final fun collect (Lorg/reactivestreams/Publisher;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun openSubscription (Lorg/reactivestreams/Publisher;I)Lkotlinx/coroutines/channels/ReceiveChannel; + public static final synthetic fun openSubscription (Lorg/reactivestreams/Publisher;I)Lkotlinx/coroutines/channels/ReceiveChannel; public static synthetic fun openSubscription$default (Lorg/reactivestreams/Publisher;IILjava/lang/Object;)Lkotlinx/coroutines/channels/ReceiveChannel; public static final fun toChannel (Lorg/reactivestreams/Publisher;I)Lkotlinx/coroutines/channels/ReceiveChannel; } @@ -22,7 +22,7 @@ public abstract interface class kotlinx/coroutines/reactive/ContextInjector { } public final class kotlinx/coroutines/reactive/ConvertKt { - public static final fun asPublisher (Lkotlinx/coroutines/channels/ReceiveChannel;Lkotlin/coroutines/CoroutineContext;)Lorg/reactivestreams/Publisher; + public static final synthetic fun asPublisher (Lkotlinx/coroutines/channels/ReceiveChannel;Lkotlin/coroutines/CoroutineContext;)Lorg/reactivestreams/Publisher; public static synthetic fun asPublisher$default (Lkotlinx/coroutines/channels/ReceiveChannel;Lkotlin/coroutines/CoroutineContext;ILjava/lang/Object;)Lorg/reactivestreams/Publisher; } diff --git a/reactive/kotlinx-coroutines-reactive/src/Await.kt b/reactive/kotlinx-coroutines-reactive/src/Await.kt index fef1205a8a..da8632bffc 100644 --- a/reactive/kotlinx-coroutines-reactive/src/Await.kt +++ b/reactive/kotlinx-coroutines-reactive/src/Await.kt @@ -106,7 +106,7 @@ public suspend fun Publisher.awaitSingle(): T = awaitOne(Mode.SINGLE) @Deprecated( message = "Deprecated without a replacement due to its name incorrectly conveying the behavior. " + "Please consider using awaitFirstOrDefault().", - level = DeprecationLevel.WARNING + level = DeprecationLevel.ERROR ) // Warning since 1.5, error in 1.6, hidden in 1.7 public suspend fun Publisher.awaitSingleOrDefault(default: T): T = awaitOne(Mode.SINGLE_OR_DEFAULT, default) @@ -135,7 +135,7 @@ public suspend fun Publisher.awaitSingleOrDefault(default: T): T = awaitO message = "Deprecated without a replacement due to its name incorrectly conveying the behavior. " + "There is a specialized version for Reactor's Mono, please use that where applicable. " + "Alternatively, please consider using awaitFirstOrNull().", - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("this.awaitSingleOrNull()", "kotlinx.coroutines.reactor") ) // Warning since 1.5, error in 1.6, hidden in 1.7 public suspend fun Publisher.awaitSingleOrNull(): T? = awaitOne(Mode.SINGLE_OR_DEFAULT) @@ -164,7 +164,7 @@ public suspend fun Publisher.awaitSingleOrNull(): T? = awaitOne(Mode.SING @Deprecated( message = "Deprecated without a replacement due to its name incorrectly conveying the behavior. " + "Please consider using awaitFirstOrElse().", - level = DeprecationLevel.WARNING + level = DeprecationLevel.ERROR ) // Warning since 1.5, error in 1.6, hidden in 1.7 public suspend fun Publisher.awaitSingleOrElse(defaultValue: () -> T): T = awaitOne(Mode.SINGLE_OR_DEFAULT) ?: defaultValue() diff --git a/reactive/kotlinx-coroutines-reactive/src/Channel.kt b/reactive/kotlinx-coroutines-reactive/src/Channel.kt index b7fbf134c5..a8db21711d 100644 --- a/reactive/kotlinx-coroutines-reactive/src/Channel.kt +++ b/reactive/kotlinx-coroutines-reactive/src/Channel.kt @@ -10,29 +10,6 @@ import kotlinx.coroutines.flow.* import kotlinx.coroutines.internal.* import org.reactivestreams.* -/** - * Subscribes to this [Publisher] and returns a channel to receive the elements emitted by it. - * The resulting channel needs to be [cancelled][ReceiveChannel.cancel] in order to unsubscribe from this publisher. - - * @param request how many items to request from the publisher in advance (optional, a single element by default). - * - * This method is deprecated in the favor of [Flow]. - * Instead of iterating over the resulting channel please use [collect][Flow.collect]: - * ``` - * asFlow().collect { value -> - * // process value - * } - * ``` - */ -@Deprecated( - message = "Transforming publisher to channel is deprecated, use asFlow() instead", - level = DeprecationLevel.ERROR) // Will be error in 1.4 -public fun Publisher.openSubscription(request: Int = 1): ReceiveChannel { - val channel = SubscriptionChannel(request) - subscribe(channel) - return channel -} - /** * Subscribes to this [Publisher] and performs the specified action for each received element. * @@ -123,3 +100,12 @@ private class SubscriptionChannel( } } +/** @suppress */ +@Deprecated( + message = "Transforming publisher to channel is deprecated, use asFlow() instead", + level = DeprecationLevel.HIDDEN) // ERROR in 1.4, HIDDEN in 1.6.0 +public fun Publisher.openSubscription(request: Int = 1): ReceiveChannel { + val channel = SubscriptionChannel(request) + subscribe(channel) + return channel +} diff --git a/reactive/kotlinx-coroutines-reactive/src/Convert.kt b/reactive/kotlinx-coroutines-reactive/src/Convert.kt index 3cb05b60fd..9492b49871 100644 --- a/reactive/kotlinx-coroutines-reactive/src/Convert.kt +++ b/reactive/kotlinx-coroutines-reactive/src/Convert.kt @@ -8,15 +8,9 @@ import kotlinx.coroutines.channels.* import org.reactivestreams.* import kotlin.coroutines.* -/** - * Converts a stream of elements received from the channel to the hot reactive publisher. - * - * Every subscriber receives values from this channel in **fan-out** fashion. If the are multiple subscribers, - * they'll receive values in round-robin way. - * @param context -- the coroutine context from which the resulting observable is going to be signalled - */ +/** @suppress */ @Deprecated(message = "Deprecated in the favour of consumeAsFlow()", - level = DeprecationLevel.ERROR, // Error in 1.4 + level = DeprecationLevel.HIDDEN, // Error in 1.4, HIDDEN in 1.6.0 replaceWith = ReplaceWith("this.consumeAsFlow().asPublisher(context)", imports = ["kotlinx.coroutines.flow.consumeAsFlow"])) public fun ReceiveChannel.asPublisher(context: CoroutineContext = EmptyCoroutineContext): Publisher = publish(context) { for (t in this@asPublisher) diff --git a/reactive/kotlinx-coroutines-reactor/src/Mono.kt b/reactive/kotlinx-coroutines-reactor/src/Mono.kt index e86d51c614..f31004b665 100644 --- a/reactive/kotlinx-coroutines-reactor/src/Mono.kt +++ b/reactive/kotlinx-coroutines-reactor/src/Mono.kt @@ -157,7 +157,7 @@ public fun CoroutineScope.mono( @Deprecated( message = "Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " + "Please use awaitSingle() instead.", - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("this.awaitSingle()") ) // Warning since 1.5, error in 1.6 public suspend fun Mono.awaitFirst(): T = awaitSingle() @@ -181,7 +181,7 @@ public suspend fun Mono.awaitFirst(): T = awaitSingle() @Deprecated( message = "Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " + "Please use awaitSingleOrNull() instead.", - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("this.awaitSingleOrNull() ?: default") ) // Warning since 1.5, error in 1.6 public suspend fun Mono.awaitFirstOrDefault(default: T): T = awaitSingleOrNull() ?: default @@ -205,7 +205,7 @@ public suspend fun Mono.awaitFirstOrDefault(default: T): T = awaitSingleO @Deprecated( message = "Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " + "Please use awaitSingleOrNull() instead.", - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("this.awaitSingleOrNull()") ) // Warning since 1.5, error in 1.6 public suspend fun Mono.awaitFirstOrNull(): T? = awaitSingleOrNull() @@ -229,7 +229,7 @@ public suspend fun Mono.awaitFirstOrNull(): T? = awaitSingleOrNull() @Deprecated( message = "Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " + "Please use awaitSingleOrNull() instead.", - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("this.awaitSingleOrNull() ?: defaultValue()") ) // Warning since 1.5, error in 1.6 public suspend fun Mono.awaitFirstOrElse(defaultValue: () -> T): T = awaitSingleOrNull() ?: defaultValue() @@ -253,7 +253,7 @@ public suspend fun Mono.awaitFirstOrElse(defaultValue: () -> T): T = awai @Deprecated( message = "Mono produces at most one value, so the last element is the same as the first. " + "Please use awaitSingle() instead.", - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("this.awaitSingle()") ) // Warning since 1.5, error in 1.6 public suspend fun Mono.awaitLast(): T = awaitSingle() diff --git a/reactive/kotlinx-coroutines-reactor/src/ReactorContext.kt b/reactive/kotlinx-coroutines-reactor/src/ReactorContext.kt index ce68091705..912fb6e577 100644 --- a/reactive/kotlinx-coroutines-reactor/src/ReactorContext.kt +++ b/reactive/kotlinx-coroutines-reactor/src/ReactorContext.kt @@ -64,11 +64,7 @@ public class ReactorContext(public val context: Context) : AbstractCoroutineCont */ public fun ContextView.asCoroutineContext(): ReactorContext = ReactorContext(this) -/** - * Wraps the given [Context] into [ReactorContext], so it can be added to the coroutine's context - * and later used via `coroutineContext[ReactorContext]`. - * @suppress - */ +/** @suppress */ @Deprecated("The more general version for ContextView should be used instead", level = DeprecationLevel.HIDDEN) public fun Context.asCoroutineContext(): ReactorContext = readOnly().asCoroutineContext() // `readOnly()` is zero-cost. diff --git a/reactive/kotlinx-coroutines-rx2/api/kotlinx-coroutines-rx2.api b/reactive/kotlinx-coroutines-rx2/api/kotlinx-coroutines-rx2.api index c27ef4d796..7cc594496e 100644 --- a/reactive/kotlinx-coroutines-rx2/api/kotlinx-coroutines-rx2.api +++ b/reactive/kotlinx-coroutines-rx2/api/kotlinx-coroutines-rx2.api @@ -16,8 +16,8 @@ public final class kotlinx/coroutines/rx2/RxAwaitKt { public final class kotlinx/coroutines/rx2/RxChannelKt { public static final fun collect (Lio/reactivex/MaybeSource;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun collect (Lio/reactivex/ObservableSource;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun openSubscription (Lio/reactivex/MaybeSource;)Lkotlinx/coroutines/channels/ReceiveChannel; - public static final fun openSubscription (Lio/reactivex/ObservableSource;)Lkotlinx/coroutines/channels/ReceiveChannel; + public static final synthetic fun openSubscription (Lio/reactivex/MaybeSource;)Lkotlinx/coroutines/channels/ReceiveChannel; + public static final synthetic fun openSubscription (Lio/reactivex/ObservableSource;)Lkotlinx/coroutines/channels/ReceiveChannel; public static final fun toChannel (Lio/reactivex/MaybeSource;)Lkotlinx/coroutines/channels/ReceiveChannel; public static final fun toChannel (Lio/reactivex/ObservableSource;)Lkotlinx/coroutines/channels/ReceiveChannel; } diff --git a/reactive/kotlinx-coroutines-rx2/src/RxAwait.kt b/reactive/kotlinx-coroutines-rx2/src/RxAwait.kt index 0e0b47ebe8..da9809c9f8 100644 --- a/reactive/kotlinx-coroutines-rx2/src/RxAwait.kt +++ b/reactive/kotlinx-coroutines-rx2/src/RxAwait.kt @@ -80,7 +80,7 @@ public suspend fun MaybeSource.awaitSingle(): T = awaitSingleOrNull() ?: */ @Deprecated( message = "Deprecated in favor of awaitSingleOrNull()", - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("this.awaitSingleOrNull()") ) // Warning since 1.5, error in 1.6, hidden in 1.7 public suspend fun MaybeSource.await(): T? = awaitSingleOrNull() @@ -102,7 +102,7 @@ public suspend fun MaybeSource.await(): T? = awaitSingleOrNull() */ @Deprecated( message = "Deprecated in favor of awaitSingleOrNull()", - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("this.awaitSingleOrNull() ?: default") ) // Warning since 1.5, error in 1.6, hidden in 1.7 public suspend fun MaybeSource.awaitOrDefault(default: T): T = awaitSingleOrNull() ?: default diff --git a/reactive/kotlinx-coroutines-rx2/src/RxChannel.kt b/reactive/kotlinx-coroutines-rx2/src/RxChannel.kt index bb093b0793..fc09bf9ee3 100644 --- a/reactive/kotlinx-coroutines-rx2/src/RxChannel.kt +++ b/reactive/kotlinx-coroutines-rx2/src/RxChannel.kt @@ -12,36 +12,6 @@ import kotlinx.coroutines.internal.* import kotlinx.coroutines.flow.* import kotlinx.coroutines.reactive.* -/** - * Subscribes to this [MaybeSource] and returns a channel to receive elements emitted by it. - * The resulting channel shall be [cancelled][ReceiveChannel.cancel] to unsubscribe from this source. - * - * This API is deprecated in the favour of [Flow]. - * [MaybeSource] doesn't have a corresponding [Flow] adapter, so it should be transformed to [Observable] first. - * @suppress - */ -@Deprecated(message = "Deprecated in the favour of Flow", level = DeprecationLevel.ERROR) // Will be hidden in 1.5 -public fun MaybeSource.openSubscription(): ReceiveChannel { - val channel = SubscriptionChannel() - subscribe(channel) - return channel -} - -/** - * Subscribes to this [ObservableSource] and returns a channel to receive elements emitted by it. - * The resulting channel shall be [cancelled][ReceiveChannel.cancel] to unsubscribe from this source. - * - * This API is deprecated in the favour of [Flow]. - * [ObservableSource] doesn't have a corresponding [Flow] adapter, so it should be transformed to [Observable] first. - * @suppress - */ -@Deprecated(message = "Deprecated in the favour of Flow", level = DeprecationLevel.ERROR) // Will be hidden in 1.5 -public fun ObservableSource.openSubscription(): ReceiveChannel { - val channel = SubscriptionChannel() - subscribe(channel) - return channel -} - /** * Subscribes to this [MaybeSource] and performs the specified action for each received element. * @@ -107,3 +77,19 @@ private class SubscriptionChannel : close(cause = e) } } + +/** @suppress */ +@Deprecated(message = "Deprecated in the favour of Flow", level = DeprecationLevel.HIDDEN) // ERROR in 1.4.0, HIDDEN in 1.6.0 +public fun ObservableSource.openSubscription(): ReceiveChannel { + val channel = SubscriptionChannel() + subscribe(channel) + return channel +} + +/** @suppress */ +@Deprecated(message = "Deprecated in the favour of Flow", level = DeprecationLevel.HIDDEN) // ERROR in 1.4.0, HIDDEN in 1.6.0 +public fun MaybeSource.openSubscription(): ReceiveChannel { + val channel = SubscriptionChannel() + subscribe(channel) + return channel +} diff --git a/reactive/kotlinx-coroutines-rx3/src/RxAwait.kt b/reactive/kotlinx-coroutines-rx3/src/RxAwait.kt index 2a14cf7c6c..754dd79484 100644 --- a/reactive/kotlinx-coroutines-rx3/src/RxAwait.kt +++ b/reactive/kotlinx-coroutines-rx3/src/RxAwait.kt @@ -81,7 +81,7 @@ public suspend fun MaybeSource.awaitSingle(): T = awaitSingleOrNull() ?: */ @Deprecated( message = "Deprecated in favor of awaitSingleOrNull()", - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("this.awaitSingleOrNull()") ) // Warning since 1.5, error in 1.6, hidden in 1.7 public suspend fun MaybeSource.await(): T? = awaitSingleOrNull() @@ -104,7 +104,7 @@ public suspend fun MaybeSource.await(): T? = awaitSingleOrNull() */ @Deprecated( message = "Deprecated in favor of awaitSingleOrNull()", - level = DeprecationLevel.WARNING, + level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("this.awaitSingleOrNull() ?: default") ) // Warning since 1.5, error in 1.6, hidden in 1.7 public suspend fun MaybeSource.awaitOrDefault(default: T): T = awaitSingleOrNull() ?: default