initialize method

  1. @override
Future<AtPersistenceBundle> initialize(
  1. String atSign,
  2. AtPersistenceConfig config
)
override

Build a fully-initialised AtPersistenceBundle for atSign.

Calling this twice for the same atSign returns the same bundle — the factory owns the per-atSign lifecycle. Callers should not try to manage it themselves.

If a previous bundle for atSign has been closed (whether directly via AtPersistenceBundle.close or via closeFor), the stale entry is dropped and a fresh bundle is built.

Throws ArgumentError if config does not match backendId.

Implementation

@override
Future<AtPersistenceBundle> initialize(
    String atSign, AtPersistenceConfig config) async {
  if (config is! DualWritePersistenceConfig) {
    throw ArgumentError('DualWriteAtPersistenceFactory expects '
        'DualWritePersistenceConfig, got ${config.runtimeType}');
  }
  final existing = _bundles[atSign];
  if (existing != null && !existing.isClosed) return existing;

  final primary = await primaryFactory.initialize(atSign, config.primary);
  final secondary =
      await secondaryFactory.initialize(atSign, config.secondary);
  final bundle = DualWriteBundle._(atSign, primary, secondary);
  _bundles[atSign] = bundle;
  return bundle;
}