mirror of https://github.com/AMT-Cheif/drift.git
Don't await StreamController.close() when closing streams
This commit is contained in:
parent
2b780492d3
commit
23585ad920
|
@ -15,6 +15,8 @@
|
||||||
- __Breaking__: Remove `customSelectStream` from `QueryEngine`. The `customSelect`
|
- __Breaking__: Remove `customSelectStream` from `QueryEngine`. The `customSelect`
|
||||||
method now returns an `Selectable` (like `customSelectQuery`, which in turn has been deprecated).
|
method now returns an `Selectable` (like `customSelectQuery`, which in turn has been deprecated).
|
||||||
- Experimentally support IndexedDB to store sqlite data on the web
|
- Experimentally support IndexedDB to store sqlite data on the web
|
||||||
|
- Moor will no longer wait for query stream listeners to receive a done event when closing a database
|
||||||
|
or transaction.
|
||||||
|
|
||||||
## 2.4.0
|
## 2.4.0
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:collection/collection.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:moor/moor.dart';
|
import 'package:moor/moor.dart';
|
||||||
import 'package:moor/src/utils/start_with_value_transformer.dart';
|
import 'package:moor/src/utils/start_with_value_transformer.dart';
|
||||||
|
import 'package:pedantic/pedantic.dart';
|
||||||
|
|
||||||
const _listEquality = ListEquality<dynamic>();
|
const _listEquality = ListEquality<dynamic>();
|
||||||
|
|
||||||
|
@ -161,8 +162,15 @@ class StreamQueryStore {
|
||||||
_isShuttingDown = true;
|
_isShuttingDown = true;
|
||||||
|
|
||||||
for (final stream in _activeKeyStreams.values) {
|
for (final stream in _activeKeyStreams.values) {
|
||||||
await stream._controller.close();
|
// Note: StreamController.close waits until the done event has been
|
||||||
|
// received by a subscriber. If there is a paused StreamSubscription on
|
||||||
|
// a query stream, this would pause forever. In particular, this is
|
||||||
|
// causing deadlocks in tests.
|
||||||
|
// https://github.com/dart-lang/test/issues/1183#issuecomment-588357154
|
||||||
|
unawaited(stream._controller.close());
|
||||||
}
|
}
|
||||||
|
// awaiting this is fine - the stream is never exposed to users and we don't
|
||||||
|
// pause any subscriptions on it.
|
||||||
await _updatedTableNames.close();
|
await _updatedTableNames.close();
|
||||||
|
|
||||||
while (_pendingTimers.isNotEmpty) {
|
while (_pendingTimers.isNotEmpty) {
|
||||||
|
@ -251,7 +259,7 @@ class QueryStream<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> close() {
|
void close() {
|
||||||
return _controller.close();
|
_controller.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,9 @@ class _TransactionStreamStore extends StreamQueryStore {
|
||||||
parent.handleTableUpdatesByName(affectedTables);
|
parent.handleTableUpdatesByName(affectedTables);
|
||||||
|
|
||||||
await super.close();
|
await super.close();
|
||||||
await Future.wait(_queriesWithoutKey.map((e) => e.close()));
|
for (final query in _queriesWithoutKey) {
|
||||||
|
query.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,6 +162,19 @@ void main() {
|
||||||
expectLater(result, throwsA(exception));
|
expectLater(result, throwsA(exception));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('database can be closed when a stream has a paused subscription',
|
||||||
|
() async {
|
||||||
|
// this test is more relevant than it seems - some test stream matchers
|
||||||
|
// leave the stream in an empty state.
|
||||||
|
final stream = db.select(db.users).watch();
|
||||||
|
final subscription = stream.listen((_) {})..pause();
|
||||||
|
|
||||||
|
await db.close();
|
||||||
|
|
||||||
|
subscription.resume();
|
||||||
|
await subscription.cancel();
|
||||||
|
});
|
||||||
|
|
||||||
group('stream keys', () {
|
group('stream keys', () {
|
||||||
final keyA = StreamKey('SELECT * FROM users;', [], User);
|
final keyA = StreamKey('SELECT * FROM users;', [], User);
|
||||||
final keyB = StreamKey('SELECT * FROM users;', [], User);
|
final keyB = StreamKey('SELECT * FROM users;', [], User);
|
||||||
|
|
Loading…
Reference in New Issue