@@ -35,7 +35,7 @@ class StreamingSyncImplementation implements StreamingSync {
35
35
final InternalConnector connector;
36
36
final ResolvedSyncOptions options;
37
37
38
- final Logger logger = isolateLogger ;
38
+ final Logger logger;
39
39
40
40
final Stream <void > crudUpdateTriggerStream;
41
41
@@ -68,14 +68,16 @@ class StreamingSyncImplementation implements StreamingSync {
68
68
required http.Client client,
69
69
Mutex ? syncMutex,
70
70
Mutex ? crudMutex,
71
+ Logger ? logger,
71
72
72
73
/// A unique identifier for this streaming sync implementation
73
74
/// A good value is typically the DB file path which it will mutate when syncing.
74
75
String ? identifier = "unknown" ,
75
76
}) : _client = client,
76
77
syncMutex = syncMutex ?? Mutex (identifier: "sync-$identifier " ),
77
78
crudMutex = crudMutex ?? Mutex (identifier: "crud-$identifier " ),
78
- _userAgentHeaders = userAgentHeaders ();
79
+ _userAgentHeaders = userAgentHeaders (),
80
+ logger = logger ?? isolateLogger;
79
81
80
82
Duration get _retryDelay => options.retryDelay;
81
83
@@ -122,6 +124,7 @@ class StreamingSyncImplementation implements StreamingSync {
122
124
@override
123
125
Future <void > streamingSync () async {
124
126
try {
127
+ assert (_abort == null );
125
128
_abort = AbortController ();
126
129
clientId = await adapter.getClientId ();
127
130
_crudLoop ();
@@ -310,7 +313,7 @@ class StreamingSyncImplementation implements StreamingSync {
310
313
var merged = addBroadcast (requestStream, _nonLineSyncEvents.stream);
311
314
312
315
Future <void >? credentialsInvalidation;
313
- bool haveInvalidated = false ;
316
+ bool shouldStopIteration = false ;
314
317
315
318
// Trigger a CRUD upload on reconnect
316
319
_internalCrudTriggerController.add (null );
@@ -336,6 +339,7 @@ class StreamingSyncImplementation implements StreamingSync {
336
339
case StreamingSyncCheckpointComplete ():
337
340
final result = await _applyCheckpoint (targetCheckpoint! , _abort);
338
341
if (result.abort) {
342
+ shouldStopIteration = true ;
339
343
return ;
340
344
}
341
345
case StreamingSyncCheckpointPartiallyComplete (: final bucketPriority):
@@ -345,6 +349,7 @@ class StreamingSyncImplementation implements StreamingSync {
345
349
// This means checksums failed. Start again with a new checkpoint.
346
350
// TODO: better back-off
347
351
// await new Promise((resolve) => setTimeout(resolve, 50));
352
+ shouldStopIteration = true ;
348
353
return ;
349
354
} else if (! result.ready) {
350
355
// If we have pending uploads, we can't complete new checkpoints
@@ -404,7 +409,7 @@ class StreamingSyncImplementation implements StreamingSync {
404
409
credentialsInvalidation ?? =
405
410
connector.prefetchCredentials ().then ((_) {
406
411
// Token has been refreshed - we should restart the connection.
407
- haveInvalidated = true ;
412
+ shouldStopIteration = true ;
408
413
// trigger next loop iteration ASAP, don't wait for another
409
414
// message from the server.
410
415
if (! aborted) {
@@ -421,7 +426,7 @@ class StreamingSyncImplementation implements StreamingSync {
421
426
}
422
427
423
428
await for (var line in merged) {
424
- if (aborted || haveInvalidated ) {
429
+ if (aborted || shouldStopIteration ) {
425
430
break ;
426
431
}
427
432
@@ -434,10 +439,10 @@ class StreamingSyncImplementation implements StreamingSync {
434
439
break ;
435
440
case TokenRefreshComplete ():
436
441
// We have a new token, so stop the iteration.
437
- haveInvalidated = true ;
442
+ shouldStopIteration = true ;
438
443
}
439
444
440
- if (haveInvalidated ) {
445
+ if (shouldStopIteration ) {
441
446
// Stop this connection, so that a new one will be started
442
447
break ;
443
448
}
0 commit comments