fromAsyncCallback<R, S> static method
Future<Result<R, S> >
fromAsyncCallback<R, S>(
- Future<
R> future(), { - required S error(
- dynamic e,
- StackTrace s
Create a Result from a callback that returns a Future.
If future
completes successfully then Result will contain its value,
and if the future
fails then its error will be contained in Result
Implementation
static Future<Result<R, S>> fromAsyncCallback<R, S>(
Future<R> Function() future, {
required S Function(dynamic e, StackTrace s) error,
}) async {
try {
return Result<R, S>.ok(await future.call());
} catch (e, s) {
return Result<R, S>.err(error(e, s));
}
}