guard<T> static method

Future<RemoteState<T>> guard<T>(
  1. Future<T> future()
)

Convert a Future to RemoteState. Emits RemoteState.success if the future completes Emits RemoteState.error if future fails.

Implementation

static Future<RemoteState<T>> guard<T>(Future<T> Function() future) async {
  try {
    return RemoteState.success(await future());
  } catch (err, stack) {
    return RemoteState.error(err, stack);
  }
}