initialize method
Initializes all internal components and establishes change subscriptions.
Idempotent: Safe to call multiple times (no-op after first call). Must be called before any data operations.
Throws StateError if called after dispose.
Implementation
Future<void> initialize() async {
if (_disposed) {
throw StateError('Cannot initialize after disposal');
}
if (_initialized) {
_logger.debug('Already initialized, skipping');
return;
}
try {
await _initializeAdapters();
_initializeSyncComponents();
_initialized = true;
await _setupAutoSyncIfEnabled();
await _subscribeToChangeStreams();
_logger.info('SynqManager initialized successfully');
} on Object catch (e, stack) {
_logger.error('Initialization failed', stack);
_emitError('', 'Initialization failed: $e', stack);
rethrow;
}
}