start method
Starts the periodic synchronization timer.
This method should be called after the LocalFirstClient.initialize completes.
It will:
- Wait for client initialization if not already complete
- Report connected state to the client
- Start the periodic sync timer with syncInterval
- Perform an immediate initial sync
Usage:
final client = LocalFirstClient(
repositories: [repository],
localStorage: storage,
syncStrategies: [periodicStrategy],
);
await client.initialize();
await periodicStrategy.start(); // Start syncing
Behavior:
- Idempotent: calling multiple times has no effect if already running
- Non-blocking: returns immediately after starting the timer
- Performs immediate sync: doesn't wait for the first interval
Exceptions: No exceptions are thrown. Sync errors are logged but don't stop the timer.
Implementation
Future<void> start() async {
if (_isRunning) return;
LocalFirstLogger.log('Starting periodic sync strategy', name: logTag);
await client.awaitInitialization;
_isRunning = true;
// Report connected state
reportConnectionState(true);
// Start periodic sync timer
_syncTimer = Timer.periodic(syncInterval, (_) => _performSync());
// Perform initial sync
await _performSync();
}