Skip to content

Commit e446934

Browse files
committed
Fix deprecation warnings in native driver
1 parent 842803c commit e446934

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

lib/native/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,11 @@ Client.prototype._pulseQueryQueue = function(initialConnection) {
209209
this._activeQuery = query;
210210
query.submit(this);
211211
var self = this;
212-
query.once('_done', function() {
212+
var pulseOnDone = function() {
213213
self._pulseQueryQueue();
214-
});
214+
query.removeListener('_done', pulseOnDone);
215+
};
216+
query._on('_done', pulseOnDone);
215217
};
216218

217219
//attempt to cancel an in-progress query

lib/native/query.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var NativeQuery = module.exports = function(config, values, callback) {
2727
//this has almost no meaning because libpq
2828
//reads all rows into memory befor returning any
2929
this._emitRowEvents = false;
30-
this.on('newListener', function(event) {
30+
this._on('newListener', function(event) {
3131
if(event === 'row') this._emitRowEvents = true;
3232
}.bind(this));
3333
};
@@ -42,18 +42,28 @@ NativeQuery._once = NativeQuery.once;
4242

4343

4444
NativeQuery.prototype.then = function(onSuccess, onFailure) {
45-
return this.promise().then(onSuccess, onFailure);
45+
return this._getPromise().then(onSuccess, onFailure);
4646
};
4747

4848
NativeQuery.prototype.catch = function(callback) {
49-
return this.promise().catch(callback);
49+
return this._getPromise().catch(callback);
5050
};
5151

5252
NativeQuery.prototype._getPromise = function() {
5353
if (this._promise) return this._promise;
5454
this._promise = new Promise(function(resolve, reject) {
55-
this._once('end', resolve);
56-
this._once('error', reject);
55+
var onEnd = function (result) {
56+
this.removeListener('error', onError);
57+
this.removeListener('end', onEnd);
58+
resolve(result);
59+
};
60+
var onError = function (err) {
61+
this.removeListener('error', onError);
62+
this.removeListener('end', onEnd);
63+
reject(err);
64+
};
65+
this._on('end', onEnd);
66+
this._on('error', onError);
5767
}.bind(this));
5868
return this._promise;
5969
};

test/integration/client/deprecation-tests.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var helper = require('./test-helper')
2-
process.noDeprecation = false
3-
process.on('warning', function () {
2+
3+
process.on('warning', function (warning) {
4+
console.log(warning)
45
throw new Error('Should not emit deprecation warning')
56
})
67

test/test-helper.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//make assert a global...
22
assert = require('assert');
33

4-
process.noDeprecation = true
5-
64
//support for node@0.10.x
75
if (typeof Promise == 'undefined') {
86
global.Promise = require('promise-polyfill')

0 commit comments

Comments
 (0)