reload method

Future<SintStatus<T>> reload({
  1. bool keepPreviousData = false,
})

Executes the loader and updates value to the resulting SintStatus.

Any earlier in-flight call is superseded so out-of-order completions never overwrite newer state.

Implementation

Future<SintStatus<T>> reload({bool keepPreviousData = false}) async {
  if (isDisposed) return peek;
  final currentRequestId = ++_requestId;
  final retained = keepPreviousData ? peek.dataOrNull : null;
  value = retained != null
      ? SintStatus<T>.refreshing(retained)
      : SintStatus<T>.loading();

  try {
    final result = await _loader();
    if (isDisposed || currentRequestId != _requestId) return peek;
    final next = (isEmpty != null && isEmpty!(result))
        ? SintStatus<T>.empty()
        : SintStatus<T>.success(result);
    value = next;
    return next;
  } catch (error, stackTrace) {
    if (isDisposed || currentRequestId != _requestId) return peek;
    final next = SintStatus<T>.error(
      error,
      previousData: retained,
      stackTrace: stackTrace,
    );
    value = next;
    return next;
  }
}