Conversation
| async function _startPolling() { | ||
| if (!_pollingIntervalId) { | ||
| // Temporarily assigning polling interval to prevent multiple polls starting while index is being created | ||
| _pollingIntervalId = -1; |
There was a problem hiding this comment.
Not sure I understand this. Does the await on line 93 not actually keep line 97 from starting the polling?
There was a problem hiding this comment.
It's to avoid a "race condition" when registerWorker is called twice in quick succession, which is what everyone will probably be doing anyway, including us.
// _pollingIntervalId is undefined
mq.registerWorker('typeOne', (queueItem) => {...});
// _startPolling called => !_pollingIntervalId === true => createIndex awaiting
mq.registerWorker('typeTwo', (queueItem) => {...});
// _startPolling called => !_pollingIntervalId === true => createIndex awaiting again
// first createIndex finishes => _pollingIntervalId updated and setInterval called
// second createIndex finishes => _pollingIntervalId changed (first one lost) and setInterval called again. This is a pretty awkward place to be creating the index as it is...
I think I would rather do a major version bump, have the database promise passed in through the constructor and do a createIndex once that gets fulfilled and then start the poller (if register worker has been called).
There was a problem hiding this comment.
Ok, that makes more sense now. Let's sleep on it and discuss further tomorrow.
|
Updated based on feedback. I need to test these changes still. |
This includes my other PR, #4. Created two to keep the review separate.
Things:
createIndexflag to true onMessageQueue