create method

  1. @override
Future<Storage> create(
  1. WorkerHandlerContext context,
  2. SyncEngineConfig config
)

Creates a storage instance for the worker thread.

Called once during worker initialization. The config provides the sync engine configuration, and context provides access to any connectors from StorageMainHandler.create.

Returns a Storage implementation that handles local persistence.

Implementation

@override
Future<Storage> create(
    WorkerHandlerContext context, SyncEngineConfig config) async {
  _log.info('DriftWorkerHandler[$id]: Creating DriftStorage...');

  _log.info('DriftWorkerHandler[$id]: Waiting for settings from main...');
  final settings = await DriftConfigConnector.receiveConfig(context, id);
  _log.info('DriftWorkerHandler[$id]: Settings received '
      '(hasWebOptions: ${settings.webOptions != null}, '
      'deduplicateOnLoad: ${settings.deduplicateOnLoad})');

  LocordaDriftNativeWorkerOptions? nativeOpts;
  if (_native) {
    _log.info(
        'DriftWorkerHandler[$id]: Requesting native options from main...');
    nativeOpts = await DriftNativeOptionsConnector.receiver(context, id);
    _log.info('DriftWorkerHandler[$id]: Native options received');
  }

  _log.info(
      'DriftWorkerHandler[$id]: All options received, creating DriftStorage...');
  final storage = await DriftStorage.create(
    web: _web ? settings.webOptions : null,
    native: nativeOpts,
    deduplicateOnLoad: settings.deduplicateOnLoad,
    perflog: context.perflog,
  );
  _log.info('DriftWorkerHandler[$id]: DriftStorage created successfully');
  return storage;
}