From 06763c81e49aafce1785c843e4f8a2ab1e286574 Mon Sep 17 00:00:00 2001 From: Louis CAD Date: Fri, 7 Jun 2019 18:32:51 +0200 Subject: [PATCH 1/2] Fix flowViaChannel closing immediately. Resolves #1259 --- kotlinx-coroutines-core/common/src/flow/Builders.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kotlinx-coroutines-core/common/src/flow/Builders.kt b/kotlinx-coroutines-core/common/src/flow/Builders.kt index 294044d875..40de975268 100644 --- a/kotlinx-coroutines-core/common/src/flow/Builders.kt +++ b/kotlinx-coroutines-core/common/src/flow/Builders.kt @@ -214,6 +214,7 @@ public fun flowViaChannel( ): Flow { return channelFlow { block(channel) + awaitClose() }.buffer(bufferSize) } @@ -327,4 +328,4 @@ private class ChannelFlowBuilder( override fun toString(): String = "block[$block] -> ${super.toString()}" -} \ No newline at end of file +} From 13b6fe3e841aac7098a5c148c000d10bbcdc59da Mon Sep 17 00:00:00 2001 From: Louis CAD Date: Sat, 8 Jun 2019 09:19:12 +0200 Subject: [PATCH 2/2] Update flowViaChannel deprecation message --- kotlinx-coroutines-core/common/src/flow/Builders.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kotlinx-coroutines-core/common/src/flow/Builders.kt b/kotlinx-coroutines-core/common/src/flow/Builders.kt index 40de975268..5c01d00973 100644 --- a/kotlinx-coroutines-core/common/src/flow/Builders.kt +++ b/kotlinx-coroutines-core/common/src/flow/Builders.kt @@ -204,10 +204,10 @@ public fun LongRange.asFlow(): Flow = flow { */ @FlowPreview @Deprecated( - message = "Use channelFlow instead", - level = DeprecationLevel.WARNING, - replaceWith = ReplaceWith("channelFlow(block)") + message = "Use channelFlow with awaitClose { } instead of flowViaChannel and invokeOnClose { }.", + level = DeprecationLevel.WARNING ) +@Suppress("DeprecatedCallableAddReplaceWith") public fun flowViaChannel( bufferSize: Int = BUFFERED, @BuilderInference block: CoroutineScope.(channel: SendChannel) -> Unit