stopAutoSync method
Stops automatic synchronization for one or all users.
Implementation
void stopAutoSync({String? userId}) {
if (userId != null) {
final timer = _autoSyncTimers.remove(userId);
timer?.cancel();
// If we are stopping a specific user's timer, also ensure it's not
// marked for resumption if the manager is paused.
if (_isSyncPaused) {
_pausedAutoSyncUserIds.remove(userId);
}
// Only add an event if the subject is not already closed, which can
// happen during a rapid dispose cycle.
if (timer != null && !_nextSyncTimeSubject.isClosed) {
_nextSyncTimeSubject.add(null);
_logger.info('Auto-sync stopped for user: $userId');
}
return;
}
for (final timer in _autoSyncTimers.values) {
timer.cancel();
}
_autoSyncTimers.clear();
// If we are stopping all timers, clear the list of users to resume.
if (_isSyncPaused) {
_pausedAutoSyncUserIds.clear();
}
if (!_nextSyncTimeSubject.isClosed) {
_nextSyncTimeSubject.add(null);
}
}