Skip to content
This repository has been archived by the owner on Mar 20, 2022. It is now read-only.

Commit

Permalink
fix(pubsub): tolerate already-deleted messages during clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
philbooth committed May 29, 2019
1 parent 2550069 commit 52d0091
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions pubsub/index.js
Expand Up @@ -265,14 +265,23 @@ function clearMessages (payload, action, forceAction = false) {
payload.forEach(event => {
// eslint-disable-next-line no-underscore-dangle
const id = event.insert_id || event._insert_id
const { message, payloadCount } = MESSAGES.get(id)
if (message) {
if (forceAction || payloadCount === 1) {
action(message)
MESSAGES.delete(id)
} else {
MESSAGES.set(id, { message, payloadCount: payloadCount - 1 })
}

const item = MESSAGES.get(id)
if (! item) {
// In this case the message has already been cleared due to an earlier failure
return
}

const { message, payloadCount } = item
if (! message) {
return
}

if (forceAction || payloadCount === 1) {
action(message)
MESSAGES.delete(id)
} else {
MESSAGES.set(id, { message, payloadCount: payloadCount - 1 })
}
})
}

0 comments on commit 52d0091

Please sign in to comment.