refreshSemesterRecords method

Future<void> refreshSemesterRecords()

Fetches fresh semester records from network and writes to DB.

The watchSemesterRecords stream automatically emits the updated value. Network errors propagate to the caller.

Concurrent calls coalesce — only the first caller triggers the actual network fetch; subsequent callers await the same Completer and receive the same result.

Implementation

Future<void> refreshSemesterRecords() async {
  if (_refreshSemesterRecordsInFlight case final existing?) {
    return existing.future;
  }

  final completer = Completer<void>();
  _refreshSemesterRecordsInFlight = completer;
  try {
    await _refreshSemesterRecords();
    completer.complete();
  } catch (e, st) {
    completer.completeError(e, st);
    rethrow;
  } finally {
    _refreshSemesterRecordsInFlight = null;
  }
}