guard method
Executes operation, setting state to loading, then success or error.
Preserves previous data during refresh when preserveData is true.
Implementation
Future<void> guard(
Future<T> Function() operation, {
bool preserveData = true,
}) async {
_preserveData = preserveData;
if (preserveData) {
state = AsyncLoading<T>().copyWithPrevious(state);
} else {
state = const AsyncLoading();
}
state = await AsyncValue.guard(operation);
}