Skip to content

Commit fdfd8af

Browse files
committed
Await crud loop before end
1 parent 102f176 commit fdfd8af

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

packages/powersync/lib/src/sync/streaming_sync.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,11 @@ class StreamingSyncImplementation implements StreamingSync {
143143
Future<void> streamingSync() async {
144144
assert(_abort == null);
145145
final abort = _abort = AbortController();
146+
Future<void> crudLoop;
146147

147148
try {
148149
clientId = await adapter.getClientId();
149-
_crudLoop().onError((error, stackTrace) {
150+
crudLoop = _crudLoop().onError((error, stackTrace) {
150151
if (aborted && error is AbortException) return;
151152

152153
logger.warning('Error in crud upload loop', error, stackTrace);
@@ -181,6 +182,10 @@ class StreamingSyncImplementation implements StreamingSync {
181182
await _delayRetry();
182183
}
183184
}
185+
186+
// Wait for the crud loop to abort as well, this mainly guarantees that we
187+
// don't leave any trailing async tasks behind.
188+
await crudLoop;
184189
} finally {
185190
abort.completeAbort();
186191
}

0 commit comments

Comments
 (0)