tryAsResultAsync<T2> function
Calls Function
f and awaits it.
Returns Ok(...) if all right
Returns Err(...) otherwise
Implementation
Future<Result<T2>> tryAsResultAsync<T2>(FutureOr<T2?> Function() f) async {
try {
var callResult = await f();
return callResult == null
? Err<T2>(StateError('async function returned null'))
: Ok(callResult);
} catch (e) {
return Err(StateError('$e'));
}
}