AsyncPersistSignalImpl<T> constructor
AsyncPersistSignalImpl<T> ({
- required Future<
T> read(), - required FutureOr<
void> write(- T value
- T initialValue()?,
- bool lazy = false,
- Duration? throttle,
- JoltDebugOption? debug,
Creates an asynchronous persistent signal.
Parameters:
read: Async function to read from storagewrite: Function to write to storageinitialValue: 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 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.debug,
}) : super(null) {
if (!lazy) {
_load();
}
}