addResult method
Add a result to the stream unless it was created
before latestResult.
Copies the QueryResult.source from the latestResult
if it is set to null.
Called internally by the QueryManager. Do not call this directly except for QueryResult.loading
Implementation
void addResult(QueryResult<TParsed> result, {bool fromRebroadcast = false}) {
// don't overwrite results due to some async/optimism issue
if (latestResult != null &&
latestResult!.timestamp.isAfter(result.timestamp)) {
return;
}
if (options.carryForwardDataOnException && result.hasException) {
result.data ??= latestResult?.data;
}
if (lifecycle == QueryLifecycle.pending && result.isConcrete) {
lifecycle = QueryLifecycle.completed;
}
latestResult = result;
// TODO should callbacks be applied before or after streaming
if (!controller.isClosed) {
controller.add(result);
}
if (result.isNotLoading) {
_applyCallbacks(result, fromRebroadcast: fromRebroadcast);
}
}