agenda
agenda copied to clipboard
fix: _unlockJobs should return when it resolves
Calling resolve
does not stop the function execution. This can lead to
the updateMany call happening even though the promise has resolved
and the promise is no longer awaiting.
For instance in this code:
await agenda.stop()
await agenda.close()
We may find that we already closed the connection when the stop code is still trying to reach the Mongo DB
Thanks for the review @pdfowler
Only nit would be to call return after calling resolve
I was curious about this one and it turns out it does not make a difference. According to the Promise costructor docs:
The executor return value is ignored.
Thus, the promise will resolve to undefined
because resolve()
is called without passing any value.
Maybe a less confusing approach would be to complete the if statement with an else
branch so that we don't really need to ~resolve~ return at all. Happy to go either way.
The more you know™ ... thanks for the reference. I think the else
approach would be overkill and this can be merged as-is.
Now to see if this will help stabilize some intermittent issues in my test suite 🤔