Skip to content

Commit 14e76da

Browse files
committed
Add comment explaining cancellation flow
1 parent 56210ae commit 14e76da

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,18 @@ class StreamingSyncImplementation implements StreamingSync {
8989
final future = abort.abort();
9090
_internalCrudTriggerController.close();
9191

92-
// This makes the merged stream emit a done event, allowing us to break
93-
// out of the loop.
92+
// If a sync iteration is active, the control flow to abort is:
93+
//
94+
// 1. We close the non-line sync event stream here.
95+
// 2. This emits a done event.
96+
// 3. `addBroadcastStream` will cancel all source subscriptions in
97+
// response to that, and then emit a done event too. If there is an
98+
// error while cancelling the stream, it's forwarded by emitting an
99+
// error before closing.
100+
// 4. We break out of the sync loop (either due to an error or because
101+
// all resources have been closed correctly).
102+
// 5. `streamingSync` completes the abort controller, which we await
103+
// here.
94104
await _nonLineSyncEvents.close();
95105

96106
// Wait for the abort to complete, which also guarantees that no requests

0 commit comments

Comments
 (0)