stopSession method

Future<ArgosDiagnosticSession?> stopSession()

Implementation

Future<ArgosDiagnosticSession?> stopSession() async {
  final session = _activeSession;
  if (session == null) return null;
  final endedAt = _latestTimestamp(
    _nowMilliseconds,
    session.startedAt,
    session.lastEventAt,
  );
  final completed = session.copyWith(
    endedAt: endedAt,
    endReason: ArgosSessionEndReason.completed,
  );
  _clearActiveSession();
  if (config?.enableStorage ?? false) {
    await ArgosPacketStorage.instance.completeSession(
      completed,
      maxSessions: config?.maxSessions ?? 5,
    );
    await ArgosPacketStorage.instance.flush();
  }
  return completed;
}