question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReceiveChannel.asFlow operator

See original GitHub issue

A missing piece of the Flow puzzle is a connection between regular ReceiveChannel and Flow (note that we already have a pretty non-obvious ReceieveChannel.asFlux) with a proper migration path for channel operators.

For example, all operators on top of the channels are deprecated, but users have no clear migration path from their channel operators sequence to flow.

The main focus here is to provide clear consumption semantics and decide whether we want to introduce such primitive at all

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
elizarovcommented, Jul 16, 2019

The proposal is to name it consumeAsFlow and add additional precaution that repeated attempts to collect from the resulting flow produce IllegalStateException just in case. See https://github.com/Kotlin/kotlinx.coroutines/blob/bc34a2e0d136d3635f6413c0e7885cf7f527f857/kotlinx-coroutines-core/common/src/flow/Channels.kt#L17-L29

0reactions
fvascocommented, Jul 16, 2019

You are right, @elizarov, I confused this use case with the example https://github.com/Kotlin/kotlinx.coroutines/issues/1326#issuecomment-509144702 , in that case asFlow drops messages (and so on… see other issue).

Read more comments on GitHub >

github_iconTop Results From Across the Web

asFlow - Kotlin
Creates a cold flow that produces values from the given array. The flow being cold means that the array components are read every...
Read more >
Going deep on Flows & Channels — Part 2 - ProAndroidDev
These operators don't execute code against the flow, instead, ... There are others, like flowOf() or asFlow(), so you can check them if...
Read more >
Change log for kotlinx.coroutines
Cancellation from flat* operators that leverage multiple coroutines is no longer ... asFlow propagates coroutine context from collect call to the Publisher.
Read more >
From Zero To Hero Series ( Kotlin Sequences, Channels ...
Various collections and sequences can be converted to flows using asFlow() extension functions. Flow example 5 — Intermediate Flow Operators.
Read more >
Co-routine flow wrapper - CommonsWare
I have an extension operator on ReceiveChannel. Can I move that extension operator ... BroadcastChannel has an asFlow() extension function.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found