feat: use timeout instead of interval for pulling
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
parent
9109c25d3d
commit
c0ca76fccf
|
@ -19,7 +19,7 @@ export const useNotificationStore = defineStore('notification', () => {
|
|||
})
|
||||
const hasUnreadNotifications = computed(() => unreadNotifications.value > 0)
|
||||
|
||||
let interval: ReturnType<typeof setInterval>
|
||||
let timeout: ReturnType<typeof setTimeout>
|
||||
|
||||
const notificationService = new NotificationService()
|
||||
|
||||
|
@ -27,14 +27,18 @@ export const useNotificationStore = defineStore('notification', () => {
|
|||
allNotifications.value = await notificationService.getAll() as INotification[]
|
||||
}
|
||||
|
||||
async function pullNotifications() {
|
||||
await loadNotifications()
|
||||
timeout = setTimeout(pullNotifications, NOTIFICATIONS_PULL_INTERVAL)
|
||||
}
|
||||
|
||||
function startNotificationPulling() {
|
||||
loadNotifications()
|
||||
interval = setInterval(loadNotifications, NOTIFICATIONS_PULL_INTERVAL)
|
||||
pullNotifications()
|
||||
return stopNotificationPulling
|
||||
}
|
||||
|
||||
function stopNotificationPulling() {
|
||||
clearInterval(interval)
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
|
||||
async function markNotificationAsRead(notificationItem: INotification): Promise<INotification | undefined> {
|
||||
|
|
Reference in New Issue
Block a user