Skip to content

Commit e1e3a24

Browse files
committed
align CLEAR_NOTIFICATIONS promises to event.waitUntil
1 parent 432b436 commit e1e3a24

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

sw/eventListener.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,13 @@ export function onMessage (sw) {
242242
return event.waitUntil(storage.removeItem('subscription'))
243243
}
244244
if (event.data.action === CLEAR_NOTIFICATIONS) {
245-
return event.waitUntil((async () => {
246-
let notifications = []
247-
try {
248-
notifications = await sw.registration.getNotifications()
249-
} catch (err) {
250-
console.error('failed to get notifications')
251-
}
245+
const promises = []
246+
promises.push(sw.registration.getNotifications().then((notifications) => {
252247
notifications.forEach(notification => notification.close())
253-
activeCount = 0
254-
return await clearAppBadge(sw)
255-
})())
248+
}))
249+
activeCount = 0
250+
promises.push(clearAppBadge(sw))
251+
event.waitUntil(Promise.all(promises))
256252
}
257253
}
258254
}

0 commit comments

Comments
 (0)