Skip to content

Commit 842803c

Browse files
authored
Fix over-eager deprecation warnings (brianc#1333)
* WIP * Remove console.log messages
1 parent f7a9461 commit 842803c

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

lib/query.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,18 @@ Query.prototype.catch = function(callback) {
5757
Query.prototype._getPromise = function () {
5858
if (this._promise) return this._promise;
5959
this._promise = new Promise(function(resolve, reject) {
60-
this._once('end', resolve);
61-
this._once('error', reject);
60+
var onEnd = function (result) {
61+
this.removeListener('error', onError);
62+
this.removeListener('end', onEnd);
63+
resolve(result);
64+
};
65+
var onError = function (err) {
66+
this.removeListener('error', onError);
67+
this.removeListener('end', onEnd);
68+
reject(err);
69+
};
70+
this._on('end', onEnd);
71+
this._on('error', onError);
6272
}.bind(this));
6373
return this._promise;
6474
};

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function normalizeQueryConfig (config, values, callback) {
139139
return config;
140140
}
141141

142-
var queryEventEmitterOverloadDeprecationMessage = 'Using the automatically created return value from client.query as an event emitter is deprecated. Please see the upgrade guide at https://node-postgres.com/guides/upgrading';
142+
var queryEventEmitterOverloadDeprecationMessage = 'Using the automatically created return value from client.query as an event emitter is deprecated and will be removed in [email protected]. Please see the upgrade guide at https://node-postgres.com/guides/upgrading';
143143

144144
var deprecateEventEmitter = function(Emitter) {
145145
var Result = function () {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var helper = require('./test-helper')
2+
process.noDeprecation = false
3+
process.on('warning', function () {
4+
throw new Error('Should not emit deprecation warning')
5+
})
6+
7+
var client = new helper.pg.Client()
8+
9+
client.connect(function (err) {
10+
if (err) throw err
11+
client.query('SELECT NOW()')
12+
.then(function (res) {
13+
client.query('SELECT NOW()', function () {
14+
client.end(function () {
15+
})
16+
})
17+
}).catch(function (err) {
18+
setImmediate(function () {
19+
throw err
20+
})
21+
})
22+
})

0 commit comments

Comments
 (0)