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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Fixed a realm generator issue, when used in concert with MobX. ([#1372](https://github.com/realm/realm-dart/pull/1372))
* Fix failed assertion for unknown app server errors (Core upgrade, since v12.9.0).
* Testing the size of a collection of links against zero would sometimes fail (sometimes = "difficult to explain"). (Core upgrade, since v13.15.1)
* `Session.getProgressStream` now returns a regular stream, instead of a broadcast stream. ([#1375](https://github.com/realm/realm-dart/pull/1375))

### Compatibility
* Realm Studio: 13.0.0 or later.
Expand Down
11 changes: 6 additions & 5 deletions lib/src/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class SyncProgress {
/// successfully transferred.
final int transferableBytes;

const SyncProgress._(this.transferredBytes, this.transferableBytes);
const SyncProgress({required this.transferredBytes, required this.transferableBytes});
}

/// A type containing information about the transition of a connection state from one value to another.
Expand Down Expand Up @@ -125,7 +125,8 @@ extension SessionInternal on Session {
realmCore.raiseError(this, category, errorCode, isFatal);
}

static SyncProgress createSyncProgress(int transferredBytes, int transferableBytes) => SyncProgress._(transferredBytes, transferableBytes);
static SyncProgress createSyncProgress(int transferredBytes, int transferableBytes) =>
SyncProgress(transferredBytes: transferredBytes, transferableBytes: transferableBytes);
}

abstract interface class ProgressNotificationsController {
Expand All @@ -144,13 +145,13 @@ class SessionProgressNotificationsController implements ProgressNotificationsCon
SessionProgressNotificationsController(this._session, this._direction, this._mode);

Stream<SyncProgress> createStream() {
_streamController = StreamController<SyncProgress>.broadcast(onListen: _start, onCancel: _stop);
_streamController = StreamController<SyncProgress>(onListen: _start, onCancel: _stop);
return _streamController.stream;
}

@override
void onProgress(int transferredBytes, int transferableBytes) {
_streamController.add(SyncProgress._(transferredBytes, transferableBytes));
_streamController.add(SyncProgress(transferredBytes: transferredBytes, transferableBytes: transferableBytes));

if (transferredBytes >= transferableBytes && _mode == ProgressMode.forCurrentlyOutstandingWork) {
_streamController.close();
Expand Down Expand Up @@ -179,7 +180,7 @@ class SessionConnectionStateController {
SessionConnectionStateController(this._session);

Stream<ConnectionStateChange> createStream() {
_streamController = StreamController<ConnectionStateChange>.broadcast(onListen: _start, onCancel: _stop);
_streamController = StreamController<ConnectionStateChange>(onListen: _start, onCancel: _stop);
return _streamController.stream;
}

Expand Down