feat: complete server-backed six-lesson app and trial tooling
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user