fromThrowable<A, B> function
FutureOr<B>
fromThrowable<A, B>(
- FutureOr<
A> f(), { - required B onSuccess(
- A a
- required B onError(
- dynamic error,
- StackTrace stackTrace
Implementation
FutureOr<B> fromThrowable<A, B>(
FutureOr<A> Function() f, {
required B Function(A a) onSuccess,
required B Function(dynamic error, StackTrace stackTrace) onError,
}) {
try {
final a = f();
if (a is Future) {
return (a as Future<A>).then(onSuccess, onError: onError);
}
return onSuccess(a);
} catch (err, stack) {
return onError(err, stack);
}
}