Skip to content

Commit 63c3551

Browse files
committed
Support multiple listeners for table updates
1 parent 4cba4f8 commit 63c3551

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

packages/sqlite_async/lib/src/utils/shared_utils.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,3 @@ class _UpdateListener {
154154
}
155155
}
156156
}
157-
158-
extension StreamUtils<T> on Stream<T> {
159-
Stream<T> pauseAfterEvent(Duration duration) async* {
160-
await for (final event in this) {
161-
yield event;
162-
await Future.delayed(duration);
163-
}
164-
}
165-
}

packages/sqlite_async/lib/src/web/worker/worker_utils.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class AsyncSqliteDatabase extends WorkerDatabase {
5656
final Map<ClientConnection, _ConnectionState> _state = {};
5757

5858
AsyncSqliteDatabase({required this.database})
59-
: _updates = database.updatedTables
60-
.pauseAfterEvent(const Duration(milliseconds: 1));
59+
: _updates = database.updatedTables;
6160

6261
_ConnectionState _findState(ClientConnection connection) {
6362
return _state.putIfAbsent(connection, _ConnectionState.new);
@@ -145,12 +144,13 @@ class AsyncSqliteDatabase extends WorkerDatabase {
145144
state.unsubscribeUpdates();
146145
_registerCloseListener(state, connection);
147146

148-
state.updatesNotification = _updates.listen((tables) {
149-
connection.customRequest(CustomDatabaseMessage(
147+
late StreamSubscription<void> subscription;
148+
subscription = state.updatesNotification = _updates.listen((tables) {
149+
subscription.pause(connection.customRequest(CustomDatabaseMessage(
150150
CustomDatabaseMessageKind.notifyUpdates,
151151
id,
152152
tables.toList(),
153-
));
153+
)));
154154
});
155155
} else {
156156
state.unsubscribeUpdates();

0 commit comments

Comments
 (0)