Skip to content

Commit 2ace4c6

Browse files
LouisCADqwwdfsad
authored andcommitted
Fix flowViaChannel closing immediately. (#1260)
Resolves #1259
1 parent ec88813 commit 2ace4c6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,17 @@ public fun LongRange.asFlow(): Flow<Long> = flow {
204204
*/
205205
@FlowPreview
206206
@Deprecated(
207-
message = "Use channelFlow instead",
208-
level = DeprecationLevel.WARNING,
209-
replaceWith = ReplaceWith("channelFlow(block)")
207+
message = "Use channelFlow with awaitClose { } instead of flowViaChannel and invokeOnClose { }.",
208+
level = DeprecationLevel.WARNING
210209
)
210+
@Suppress("DeprecatedCallableAddReplaceWith")
211211
public fun <T> flowViaChannel(
212212
bufferSize: Int = BUFFERED,
213213
@BuilderInference block: CoroutineScope.(channel: SendChannel<T>) -> Unit
214214
): Flow<T> {
215215
return channelFlow<T> {
216216
block(channel)
217+
awaitClose()
217218
}.buffer(bufferSize)
218219
}
219220

@@ -327,4 +328,4 @@ private class ChannelFlowBuilder<T>(
327328

328329
override fun toString(): String =
329330
"block[$block] -> ${super.toString()}"
330-
}
331+
}

0 commit comments

Comments
 (0)