@@ -48,8 +48,7 @@ class StreamingSyncImplementation implements StreamingSync {
48
48
49
49
final http.Client _client;
50
50
51
- @visibleForTesting
52
- final SyncStatusStateStream state = SyncStatusStateStream ();
51
+ final SyncStatusStateStream _state = SyncStatusStateStream ();
53
52
54
53
AbortController ? _abort;
55
54
@@ -81,7 +80,7 @@ class StreamingSyncImplementation implements StreamingSync {
81
80
Duration get _retryDelay => options.retryDelay;
82
81
83
82
@override
84
- Stream <SyncStatus > get statusStream => state .statusStream;
83
+ Stream <SyncStatus > get statusStream => _state .statusStream;
85
84
86
85
@override
87
86
Future <void > abort () async {
@@ -105,7 +104,7 @@ class StreamingSyncImplementation implements StreamingSync {
105
104
await _nonLineSyncEvents.close ();
106
105
107
106
_client.close ();
108
- state .close ();
107
+ _state .close ();
109
108
}
110
109
}
111
110
@@ -121,7 +120,7 @@ class StreamingSyncImplementation implements StreamingSync {
121
120
_crudLoop ();
122
121
var invalidCredentials = false ;
123
122
while (! aborted) {
124
- state .updateStatus ((s) => s.setConnectingIfNotConnected ());
123
+ _state .updateStatus ((s) => s.setConnectingIfNotConnected ());
125
124
try {
126
125
if (invalidCredentials) {
127
126
// This may error. In that case it will be retried again on the next
@@ -143,7 +142,7 @@ class StreamingSyncImplementation implements StreamingSync {
143
142
logger.warning ('Sync error: $message ' , e, stacktrace);
144
143
invalidCredentials = true ;
145
144
146
- state .updateStatus ((s) => s.applyDownloadError (e));
145
+ _state .updateStatus ((s) => s.applyDownloadError (e));
147
146
148
147
// On error, wait a little before retrying
149
148
// When aborting, don't wait
@@ -189,7 +188,7 @@ class StreamingSyncImplementation implements StreamingSync {
189
188
// This is the first item in the FIFO CRUD queue.
190
189
CrudEntry ? nextCrudItem = await adapter.nextCrudItem ();
191
190
if (nextCrudItem != null ) {
192
- state .updateStatus ((s) => s.uploading = true );
191
+ _state .updateStatus ((s) => s.uploading = true );
193
192
if (nextCrudItem.clientId == checkedCrudItem? .clientId) {
194
193
// This will force a higher log level than exceptions which are caught here.
195
194
logger.warning (
@@ -202,7 +201,7 @@ class StreamingSyncImplementation implements StreamingSync {
202
201
203
202
checkedCrudItem = nextCrudItem;
204
203
await connector.uploadCrud ();
205
- state .updateStatus ((s) => s.uploadError = null );
204
+ _state .updateStatus ((s) => s.uploadError = null );
206
205
} else {
207
206
// Uploading is completed
208
207
await adapter.updateLocalTarget (() => getWriteCheckpoint ());
@@ -211,10 +210,10 @@ class StreamingSyncImplementation implements StreamingSync {
211
210
} catch (e, stacktrace) {
212
211
checkedCrudItem = null ;
213
212
logger.warning ('Data upload error' , e, stacktrace);
214
- state .updateStatus ((s) => s.applyUploadError (e));
213
+ _state .updateStatus ((s) => s.applyUploadError (e));
215
214
await _delayRetry ();
216
215
217
- if (! state .status.connected) {
216
+ if (! _state .status.connected) {
218
217
// Exit the upload loop if the sync stream is no longer connected
219
218
break ;
220
219
}
@@ -223,7 +222,7 @@ class StreamingSyncImplementation implements StreamingSync {
223
222
e,
224
223
stacktrace);
225
224
} finally {
226
- state .updateStatus ((s) => s.uploading = false );
225
+ _state .updateStatus ((s) => s.uploading = false );
227
226
}
228
227
}
229
228
}, timeout: _retryDelay).whenComplete (() {
@@ -264,7 +263,7 @@ class StreamingSyncImplementation implements StreamingSync {
264
263
}
265
264
266
265
void _updateStatusForPriority (SyncPriorityStatus completed) {
267
- state .updateStatus ((s) {
266
+ _state .updateStatus ((s) {
268
267
// All status entries with a higher priority can be deleted since this
269
268
// partial sync includes them.
270
269
s.priorityStatusEntries = [
@@ -325,7 +324,7 @@ class StreamingSyncImplementation implements StreamingSync {
325
324
bucketMap = newBuckets;
326
325
await adapter.removeBuckets ([...bucketsToDelete]);
327
326
final initialProgress = await adapter.getBucketOperationProgress ();
328
- state .updateStatus (
327
+ _state .updateStatus (
329
328
(s) => s.applyCheckpointStarted (initialProgress, line));
330
329
case StreamingSyncCheckpointComplete ():
331
330
final result = await _applyCheckpoint (targetCheckpoint! , _abort);
@@ -376,7 +375,7 @@ class StreamingSyncImplementation implements StreamingSync {
376
375
writeCheckpoint: diff.writeCheckpoint);
377
376
targetCheckpoint = newCheckpoint;
378
377
final initialProgress = await adapter.getBucketOperationProgress ();
379
- state .updateStatus (
378
+ _state .updateStatus (
380
379
(s) => s.applyCheckpointStarted (initialProgress, newCheckpoint));
381
380
382
381
bucketMap = newBuckets.map ((name, checksum) =>
@@ -386,7 +385,7 @@ class StreamingSyncImplementation implements StreamingSync {
386
385
case SyncDataBatch ():
387
386
// TODO: This increments the counters before actually saving sync
388
387
// data. Might be fine though?
389
- state .updateStatus ((s) => s.applyBatchReceived (line));
388
+ _state .updateStatus ((s) => s.applyBatchReceived (line));
390
389
await adapter.saveSyncData (line);
391
390
case StreamingSyncKeepalive (: final tokenExpiresIn):
392
391
if (tokenExpiresIn == 0 ) {
@@ -421,6 +420,7 @@ class StreamingSyncImplementation implements StreamingSync {
421
420
422
421
switch (line) {
423
422
case ReceivedLine (: final line):
423
+ _state.updateStatus ((s) => s.setConnected ());
424
424
await handleLine (line as StreamingSyncLine );
425
425
case UploadCompleted ():
426
426
// Only relevant for the Rust sync implementation.
@@ -433,7 +433,6 @@ class StreamingSyncImplementation implements StreamingSync {
433
433
throw AssertionError ('unreachable' );
434
434
}
435
435
436
- state.updateStatus ((s) => s.setConnected ());
437
436
if (haveInvalidated) {
438
437
// Stop this connection, so that a new one will be started
439
438
break ;
@@ -473,7 +472,7 @@ class StreamingSyncImplementation implements StreamingSync {
473
472
if (result.checkpointValid && result.ready) {
474
473
logger.fine ('validated checkpoint: $targetCheckpoint ' );
475
474
476
- state .updateStatus ((s) => s.applyCheckpointReached (targetCheckpoint));
475
+ _state .updateStatus ((s) => s.applyCheckpointReached (targetCheckpoint));
477
476
478
477
return const (abort: false , didApply: true );
479
478
} else {
0 commit comments