Skip to content

Commit 0f39f09

Browse files
authored
Merge pull request #267 from powersync-ja/refactor-connection-locks
Refactor connection locks
2 parents 12d6188 + 087b5d5 commit 0f39f09

10 files changed

+358
-228
lines changed

packages/powersync_core/lib/src/abort_controller.dart

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class AbortController {
1414
return _abortRequested.future;
1515
}
1616

17+
Future<void> get onCompletion {
18+
return _abortCompleter.future;
19+
}
20+
1721
/// Abort, and wait until aborting is complete.
1822
Future<void> abort() async {
1923
aborted = true;

packages/powersync_core/lib/src/database/active_instances.dart

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@ final class ActiveDatabaseGroup {
1818

1919
/// Use to prevent multiple connections from being opened concurrently
2020
final Mutex syncConnectMutex = Mutex();
21+
final Mutex syncMutex;
22+
final Mutex crudMutex;
23+
2124
final String identifier;
2225

23-
ActiveDatabaseGroup._(this.identifier);
26+
ActiveDatabaseGroup._(this.identifier)
27+
: syncMutex = Mutex(identifier: '$identifier-sync'),
28+
crudMutex = Mutex(identifier: '$identifier-crud');
2429

25-
void close() {
30+
Future<void> close() async {
2631
if (--refCount == 0) {
2732
final removedGroup = _activeGroups.remove(identifier);
2833
assert(removedGroup == this);
34+
35+
await syncConnectMutex.close();
36+
await syncMutex.close();
37+
await crudMutex.close();
2938
}
3039
}
3140

0 commit comments

Comments
 (0)