Skip to content
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

Avoid StreamController.broadcast #1375

Merged
merged 4 commits into from
Aug 16, 2023
Merged

Avoid StreamController.broadcast #1375

merged 4 commits into from
Aug 16, 2023

Conversation

nielsenko
Copy link
Contributor

There are a number of reasons to prefer not to use broadcast stream here.

  1. You can always turn a normal stream into a broadcast stream with asBroadcast, but it is impossible to go the other way.
  2. We are not actually sharing the progress stream (and hence the backing StreamController). Each call to getProgressStream will create a new one anyway, so unless the user explicitly shares the returned stream there is no sharing. Fx. our own tests pass just fine, when converting to a normal stream.
  3. The SessionProgressNotificationController owning the StreamController (and hence the Stream) is passed to native and become a GC root, preventing the GC to collect until realm-core releases it. Unlike single-subscriber streams which are constructed for one-time-use, a broadcast stream is useful to pass around a be subscribed multiple times. If a single cancel call is missed, we have leak.
  4. A pause on a subscription on a broadcast stream will cause events to be lost while paused. Recall that dart will implicitly pause stream during await for loops. I believe it is important that people opt-in to this.

Copy link
Contributor

@blagoev blagoev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be an argument to never return a broadcast stream from any API. To me it is more of a user limitation and single listener streams should be exposed only when explicitly required by the API.
Since this was exposed to the user as a Stream we used a broadcast stream to allow multiple listeners by default. This also covers single listener case and does not require addition call to asBoradcast stream.
Also isn't this a breaking change.

Happy to discuss this on the round table. Perhaps we could decide to change it.

lib/src/session.dart Outdated Show resolved Hide resolved
Base automatically changed from blagoev/realmOpenAsync to main August 14, 2023 09:42
@coveralls
Copy link

coveralls commented Aug 15, 2023

Pull Request Test Coverage Report for Build 5875858867

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 89.005%

Files with Coverage Reduction New Missed Lines %
lib/src/session.dart 6 83.56%
Totals Coverage Status
Change from base Build 5867151472: 0.03%
Covered Lines: 3311
Relevant Lines: 3720

💛 - Coveralls

CHANGELOG.md Outdated Show resolved Hide resolved
@nielsenko nielsenko merged commit c1a339b into main Aug 16, 2023
48 checks passed
@nielsenko nielsenko deleted the kn/fix-progress-stream branch August 16, 2023 10:45
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants