guardFuture<T> method
Future<T>
guardFuture<T>(})
Guard an async operation and route failures into this boundary.
Implementation
Future<T> guardFuture<T>(
Future<T> Function() action, {
String? source,
FutureOr<void> Function(T value)? onSuccess,
FutureOr<void> Function(BaseException e)? onError,
}) async {
final res = await guard<T>(
action,
source: source,
onSuccess: onSuccess,
onError: (e) async {
await onError?.call(e);
_setError(e);
},
);
return res.match(
ok: (v) => v,
err: (e) => throw e, // propagate, while boundary shows fallback
);
}