AsyncPersistSignalImpl<T> constructor

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

Creates an asynchronous persistent signal.

Parameters:

  • read: Async function to read from storage
  • write: Function to write to storage
  • initialValue: Optional temporary value during loading (null if omitted)
  • lazy: Defer loading until first access (default: false)
  • throttle: Delay before writing (null = no throttling)
  • onDebug: Optional debug callback

Example:

final theme = PersistSignal.async(
  read: () async => await prefs.getString('theme') ?? 'light',
  write: (value) => prefs.setString('theme', value),
  initialValue: () => 'light',  // Show while loading
);

Implementation

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