updateWith method
Updates the beacon with the result of the compute.
If the beacon is reset before compute finishes,
the result of compute will be ignored.
If multiple calls to updateWith is made, they will be queued and execute in FIFO order.
If the beacon is set to idle with .idle() before compute finishes,
the result of compute will be ignored.
If optimisticResult is provided, it will be set immediately instead of
setting the loading state. If an error occurs, the .lastData of the
error will be set to the previous state before the optimistic update.
Implementation
Future<void> updateWith(
FutureCallback<T> compute, {
T? optimisticResult,
}) async {
final completer = Completer<void>();
final previousQueue = _updateQueue;
_updateQueue = completer.future;
final loadCount = _loadCount;
try {
await previousQueue;
if (loadCount == _loadCount) {
await _performUpdate(compute, optimisticResult: optimisticResult);
}
} finally {
completer.complete();
}
}