This repository was archived by the owner on Dec 30, 2019. It is now read-only.
Don’t create promises when callbacks are provided - #31
Merged
Merged
Conversation
This reverts commit 6a7edab. The callback passed to `Pool.prototype.connect` should be responsible for handling connection errors. The `error` event is documented to be: > Emitted whenever an idle client in the pool encounters an error. This isn’t the case of an idle client in the pool; it never makes it into the pool. It also breaks tests on pg’s master because of nonspecific dependencies.
charmander
force-pushed
the
promise-xor-callback
branch
from
October 28, 2016 06:16
cdf7691 to
1be1802
Compare
It’s incorrect to do so. One consequence is that a rejected promise will be unhandled, which is currently annoying, but also dangerous in the future: > DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. The way callbacks are used currently also causes brianc#24 (hiding of errors thrown synchronously from the callback). One fix for that would be to call them asynchronously from inside the `new Promise()` executor: process.nextTick(cb, error); I don’t think it’s worth implementing, though, since it would still be backwards-incompatible – just less obvious about it. Also fixes a bug where the `Pool.prototype.connect` callback would be called twice if there was an error.
Contributor
|
I would +1 this feature but please don't revoke my error emition code. Not in this PR at least. |
This was referenced Oct 28, 2016
Owner
|
Thank you so much for this PR @charmander - sorry it took me a while to get to it. A bout of open source burnout as well as a long much needed vacation. :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
One consequence is that a rejected promise will be unhandled, which is currently annoying, but also dangerous in the future:
The way callbacks are used currently also causes #24 (hiding of errors thrown synchronously from the callback). One fix for that would be to call them asynchronously from inside the
new Promise()executor:I don’t think it’s worth implementing, though, since it would still be backwards-incompatible – just less obvious about it.
Should fix CI failures in brianc/node-postgres’s pull requests (and on master if it were run again), and also fix #24.
Also fixes a bug where the
Pool.prototype.connectcallback would be called twice if there was an error.