New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flow multiplexing #4103
Labels
Comments
odedniv
added a commit
to odedniv/kotlinx.coroutines
that referenced
this issue
Apr 17, 2024
This is useful when the source allows only a single subscription, but the data is needed by multiple users. Fixing Kotlin#4103.
Ignore the specific commit referenced above, see master...odedniv:kotlinx.coroutines:multiplex for the most up to date proposal. |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case
set...Callback
rather thanadd...Callback
).Set
).The Shape of the API
Example implementation and API can be seen in master...odedniv:kotlinx.coroutines:multiplex. Generally:
Prior Art
This is similar to a
SharedFlow
, except for these distinctions:Because of these distinctions, there would have to be multiple
SharedFlow
s, which would be hard to get right if there's only a single data source for all of them. Note that the suggested implementation in master...odedniv:kotlinx.coroutines:multiplex is actually based on maintaining multipleSharedFlow
s, each feeding the specific users.Implementing this is very error prone, around both thread safety and lifecycle (e.g. rollback when a new user requested data that fails to be fetched). It took many cycles in my project to get this right, so I thought it would be a good idea to have an implementation in
kotlinx.coroutines
.The text was updated successfully, but these errors were encountered: