resolve method
Resolves the computation and returns the value (as V) or a Future.
If already resolved, returns the cached value or rethrows the cached error. If a resolution is in progress, returns the same Future.
Implementation
FutureOr<V> resolve() {
var result = _result;
if (result != null) {
var error = result.error;
if (error != null) {
Error.throwWithStackTrace(error, result.stackTrace!);
}
return result.value as V;
}
var future = _future;
if (future != null) return future;
final FutureOr<V> call;
try {
var computer = _call ?? (throw StateError("Null `_call`"));
call = computer();
if (call is Future<V>) {
future = _future = call;
future.then(
(value) {
_result = (value: value, error: null, stackTrace: null);
if (identical(future, _future)) {
_future = null;
}
_call = null;
},
onError: (e, s) {
_result = (value: null, error: e, stackTrace: s);
if (identical(future, _future)) {
_future = null;
}
_call = null;
},
);
return future;
} else {
_result = (value: call, error: null, stackTrace: null);
_call = null;
return call;
}
} catch (e, s) {
_result = (value: null, error: e, stackTrace: s);
_call = null;
rethrow;
}
}