resolveAsync method
Future<V>
resolveAsync({
- bool throwError = true,
- Future<
V> onError(- Object error,
- StackTrace stackTrace
- V? onErrorValue,
Resolves the computation asynchronously.
Always returns a Future<V> that completes with the resolved value or completes with an error.
- If a resolution is in progress, returns the same in-flight Future.
- If already resolved, returns an already completed Future.
- When the computation completes (success or failure), onCompute is invoked with the resulting value or error.
Parameters:
-
throwError: Whentrue(default), the returned Future completes with the original error and StackTrace. Whenfalse, errors are handled byonErrororonErrorValue. -
onError: Optional asynchronous error handler used only whenthrowErrorisfalse. Receives the error object and its StackTrace and must return a Future<V> whose value becomes the resolution result. -
onErrorValue: Fallback value (default null) used to complete the returned Future when an error occurs,throwErrorisfalse, andonErroris not provided.
Implementation
Future<V> resolveAsync({
bool throwError = true,
Future<V> Function(Object error, StackTrace stackTrace)? onError,
V? onErrorValue,
}) {
var result = _result;
if (result != null) {
var error = result.error;
if (error != null) {
var stackTrace = result.stackTrace!;
if (throwError) {
return Future.error(error, stackTrace);
} else if (onError != null) {
return onError(error, stackTrace);
} else {
return Future.value(onErrorValue ?? (null as V));
}
}
return Future.value(result.value as V);
}
var future = _future;
if (future != null) {
if (!throwError) {
if (onError != null) {
return future.catchError(onError);
} else {
return future.catchError((e, s) => _castErrorValue(onErrorValue));
}
}
return future;
}
var computer = _call ?? (throw StateError("Null `_call`"));
future = _future = Future(computer);
final posCompute = this.posCompute;
if (posCompute != null) {
future = _future = future.then((v) {
return posCompute(v, null, null);
}, onError: (e, s) {
return posCompute(null, e, s);
});
}
return _resolveFuture(future, throwError, onError, onErrorValue);
}