SyncPersistSignalImpl<T> constructor

SyncPersistSignalImpl<T>({
  1. required T read(),
  2. required FutureOr<void> write(
    1. T value
    ),
  3. bool lazy = false,
  4. Duration? throttle,
  5. JoltDebugFn? onDebug,
})

Creates a synchronous persistent signal.

Parameters:

  • read: Synchronous function to read from storage
  • write: Function to write to storage
  • lazy: Defer loading until first access (default: false)
  • throttle: Delay before writing (null = no throttling)
  • onDebug: Optional debug callback

Example:

final theme = PersistSignal.sync(
  read: () => prefs.getString('theme') ?? 'light',
  write: (value) => prefs.setString('theme', value),
);

Implementation

SyncPersistSignalImpl({
  required this.read,
  required this.write,
  bool lazy = false,
  this.throttle,
  super.onDebug,
}) : super(null) {
  if (!lazy) {
    _loadSync();
  }
}