sync method
Performs full sync.
Implementation
@override
Future<void> sync() async {
// Coalesce rapid sync calls: if a sync is already in-flight, just flag that
// another round is needed. When the current sync finishes it will see the
// flag and run once more — catching any data that arrived in the meantime.
if (_isSyncing) {
_syncPending = true;
ChatLogger.info('Sync already in progress — deferred');
return;
}
_isSyncing = true;
try {
await _doSync();
// Catch-up: if another sync was requested while we were running, do one
// final round to pick up anything that arrived in the window.
if (_syncPending) {
_syncPending = false;
ChatLogger.info('Running deferred catch-up sync');
await _doSync();
}
} finally {
_isSyncing = false;
}
}