guard method

Future<void> guard(
  1. Future<T> operation(), {
  2. bool preserveData = true,
})

Implementation

Future<void> guard(
  Future<T> Function() operation, {
  bool preserveData = true,
}) async {
  if (preserveData) {
    state = AsyncLoading<T>().copyWithPrevious(state);
  } else {
    state = const AsyncLoading();
  }
  state = await AsyncValue.guard(operation);
}