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.

Provide abstraction for cold streams

See original GitHub issue

All the currently provided channel abstractions in kotlinx.coroutines are hot. The data is being produced regardless of the presence of subscriber. This is good for data sources and applications that are inherently hot, like incoming network and UI-events.

However, hot streams are not an ideal solution for cases where data stream is produced on demand. Consider, for example, the following simple code that produces ReceiveChannel<Int>:

produce<Int> { 
    while (true) {
        val x = computeNextValue()
        send(x)
    } 
}

One obvious downside is the computeNextValue() is invoked before send, so even when receiver is not ready, the next value gets computed. Of course, it gets suspended in send if there is no receiver, but it is not as lazy as you get with cold reactive Publisher/Observable/Flowable/Flux/Flow.

We need the abstraction for cold streams in kotlinx.coroutines that is going to be just as lazy, computing data in “push” mode versus “pull” mode of hot channels that we have now.

There are the following related discussions:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:91
  • Comments:116 (78 by maintainers)

github_iconTop GitHub Comments

28reactions
qwwdfsadcommented, Mar 16, 2019

We are actively working on it. We have finished the design phase and resolved most of the issues related to API surface and mental model; now we are prototyping it, the first eap build will arrive at the beginning of April (though I am not sure this one will be publicly announced and merged into upstream as “ready to use” feature)

20reactions
elizarovcommented, Mar 30, 2019

It had changed somewhat:

  • It is going to be named Flow<T>
  • We will not make all the channel types implement Flow<T>, but provide .asFlow() converters for all the appropriate types instead.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Flow default operators does not expose the context?
Provide abstraction for cold streams ... All the currently provided channel abstractions in `kotlinx.coroutines` are _hot…_.
Read more >
Intro To Reactor Core - Baeldung
Currently, we've focused primarily on cold streams. These are static, fixed-length streams that are easy to deal with. A more realistic use case ......
Read more >
Kotlin flows on Android - Android Developers
Flows are built on top of coroutines and can provide multiple values. A flow is conceptually a stream of data that can be...
Read more >
The small covering factor of cold accretion streams
Abstract. Theoretical models of galaxy formation predict that galaxies acquire most of their baryons via cold mode accretion. Observations of high-redshift ...
Read more >
How to Use Java Streams Explained | Capital One
There are a lot of benefits to using streams in Java, such as the ability to write functions at a more abstract level...
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