Files
gold_land_user/src/modules/gold-land/services/goldLandProgressSync.ts
T
safavimohadeseh78andCursor e3f0457dc9
Frontend CI / unit (test, type-check, build) (push) Successful in 1m11s
Frontend CI / browser E2E (frontend + pinned backend) (push) Failing after 2m48s
feat: complete server-backed six-lesson app and trial tooling
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-12 14:40:37 +03:30

29 lines
885 B
TypeScript

import { api } from '@/api/client'
import { StaleSessionError } from '@/api/errors'
import type { GoldLandProgressResponse } from '../types/goldLand.types'
/** Monotonic seq so an older in-flight progress response cannot overwrite a newer one (same session). */
let progressRequestSeq = 0
let lastCommittedProgressSeq = 0
let progressEpoch = 0
export function resetGoldLandProgressSync(): void {
progressRequestSeq = 0
lastCommittedProgressSeq = 0
progressEpoch += 1
}
export async function fetchGoldLandProgress(): Promise<GoldLandProgressResponse> {
const epochAtStart = progressEpoch
const seq = ++progressRequestSeq
const data = await api.getGoldLandProgress()
if (epochAtStart !== progressEpoch) {
throw new StaleSessionError()
}
if (seq < lastCommittedProgressSeq) {
throw new StaleSessionError()
}
lastCommittedProgressSeq = seq
return data
}