fix: coalesce concurrent notification count reads
This commit is contained in:
@@ -9,7 +9,19 @@ export const useNotificationsStore = defineStore('client-notifications', () => {
|
||||
|
||||
const hasUnread = computed(() => (unreadCount.value ?? 0) > 0)
|
||||
|
||||
async function refreshUnreadCount() {
|
||||
let pending: Promise<void> | null = null
|
||||
|
||||
async function refreshUnreadCount(afterMutation = false): Promise<void> {
|
||||
if (pending) {
|
||||
if (!afterMutation) return pending
|
||||
await pending
|
||||
return refreshUnreadCount()
|
||||
}
|
||||
pending = loadUnreadCount().finally(() => { pending = null })
|
||||
return pending
|
||||
}
|
||||
|
||||
async function loadUnreadCount() {
|
||||
loading.value = true
|
||||
errorMessage.value = ''
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user