PersistSignal<T>.async constructor

PersistSignal<T>.async({
  1. required Future<T> read(),
  2. required FutureOr<void> write(
    1. T value
    ),
  3. T initialValue()?,
  4. bool lazy,
  5. Duration? throttle,
  6. JoltDebugOption? debug,
})

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)
  • debug: Optional debug options

Example:

final counter = PersistSignal.async(
  read: () async => await prefs.getInt('counter') ?? 0,
  write: (value) => prefs.setInt('counter', value),
  initialValue: () => 0,  // Show while loading
);

Implementation

factory PersistSignal.async({
  required Future<T> Function() read,
  required FutureOr<void> Function(T value) write,
  T Function()? initialValue,
  bool lazy,
  Duration? throttle,
  JoltDebugOption? debug,
}) = AsyncPersistSignalImpl<T>;