game-village-politics-frontend/app/composables/useNow.ts

9 lines
279 B
TypeScript
Raw Normal View History

const now = ref(Date.now())
let timer: ReturnType<typeof setInterval> | undefined
/** A shared clock for projections and countdowns, ticking four times a second. */
export function useNow() {
timer ??= setInterval(() => (now.value = Date.now()), 250)
return readonly(now)
}