Skip to content
Permalink
Browse files

fix(pubsub): tolerate already-deleted messages during clean-up

  • Loading branch information...
philbooth committed May 29, 2019
1 parent 2550069 commit 52d00916ab1ed40762661145989cb698c049d74d
Showing with 17 additions and 8 deletions.
  1. +17 −8 pubsub/index.js
@@ -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.
You can’t perform that action at this time.