Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Errors in Queue Tasks to reject Promise #7

Merged
merged 5 commits into from Nov 24, 2015

Conversation

EricByers
Copy link
Contributor

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

@EricByers EricByers changed the title Adding Second 'then' to relay errors to original task promise Allow Errors in Queue Tasks to reject Promise Nov 18, 2015
Eric Byers added 3 commits November 17, 2015 23:00
…rn in the correct order. Fixing tests that incorrectly accounted for offset (ie 10 items added, expected 10 after first item complete)
…xception when it is the second item in the queue (to make sure it is triggered form the dequeue and not the add, and one for promise handling order after exception is thrown
azproduction added a commit that referenced this pull request Nov 24, 2015
Allow Errors in Queue Tasks to reject Promise
@azproduction azproduction merged commit f60612a into promise-queue:master Nov 24, 2015
@azproduction
Copy link
Collaborator

Hey, thank you for the pull request! Sorry that it took so much time to review!
promise-queue@2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants