You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Don’t create promises when callbacks are provided (#31)
* Revert "When connection fail, emit the error. (#28)"
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.
* Don’t create promises when callbacks are provided
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 #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.
* Use Node-0.10-compatible `process.nextTick`
0 commit comments