Allow Errors in Queue Tasks to reject Promise #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since some promise libraries automatically convert an exception into a rejection, and because the promise returned from the queue is not the same one that is used by the queue management, it was causing the exception to be completely dropped.
First attempt to fix this was adding a second
then
handler, which worked, however caused a couple of new issues, because the rejection is handled in the calling context, the item that is rejected is the previous queue item. Getting the next queue item looks to be complex and would potentially have issues with queues that run more than 1 item at a time.So since promises already essentially wrap a try catch, we wrap this around the main calling stack in dequeue, this allows the exception to be handled in the same stack it was thrown in, everything gets called in the correct order. This should mean the try/catch example in the README is no longer needed as it will handle it internally automatically and pass it to the reject, instead of only try/catching only when the queue was empty when it was added.
This should resolve the issue in #6