From e4469340aee6703eaa9f1879b82d7eeab99a441e Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Tue, 20 Jun 2017 09:17:27 -0500 Subject: [PATCH] Fix deprecation warnings in native driver --- lib/native/index.js | 6 ++++-- lib/native/query.js | 20 +++++++++++++++----- test/integration/client/deprecation-tests.js | 5 +++-- test/test-helper.js | 2 -- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/native/index.js b/lib/native/index.js index 99c029f..4735009 100644 --- a/lib/native/index.js +++ b/lib/native/index.js @@ -209,9 +209,11 @@ Client.prototype._pulseQueryQueue = function(initialConnection) { this._activeQuery = query; query.submit(this); var self = this; - query.once('_done', function() { + var pulseOnDone = function() { self._pulseQueryQueue(); - }); + query.removeListener('_done', pulseOnDone); + }; + query._on('_done', pulseOnDone); }; //attempt to cancel an in-progress query diff --git a/lib/native/query.js b/lib/native/query.js index 3d6b3c0..88e19f5 100644 --- a/lib/native/query.js +++ b/lib/native/query.js @@ -27,7 +27,7 @@ var NativeQuery = module.exports = function(config, values, callback) { //this has almost no meaning because libpq //reads all rows into memory befor returning any this._emitRowEvents = false; - this.on('newListener', function(event) { + this._on('newListener', function(event) { if(event === 'row') this._emitRowEvents = true; }.bind(this)); }; @@ -42,18 +42,28 @@ NativeQuery._once = NativeQuery.once; NativeQuery.prototype.then = function(onSuccess, onFailure) { - return this.promise().then(onSuccess, onFailure); + return this._getPromise().then(onSuccess, onFailure); }; NativeQuery.prototype.catch = function(callback) { - return this.promise().catch(callback); + return this._getPromise().catch(callback); }; NativeQuery.prototype._getPromise = function() { if (this._promise) return this._promise; this._promise = new Promise(function(resolve, reject) { - this._once('end', resolve); - this._once('error', reject); + var onEnd = function (result) { + this.removeListener('error', onError); + this.removeListener('end', onEnd); + resolve(result); + }; + var onError = function (err) { + this.removeListener('error', onError); + this.removeListener('end', onEnd); + reject(err); + }; + this._on('end', onEnd); + this._on('error', onError); }.bind(this)); return this._promise; }; diff --git a/test/integration/client/deprecation-tests.js b/test/integration/client/deprecation-tests.js index 39160d5..21decc4 100644 --- a/test/integration/client/deprecation-tests.js +++ b/test/integration/client/deprecation-tests.js @@ -1,6 +1,7 @@ var helper = require('./test-helper') -process.noDeprecation = false -process.on('warning', function () { + +process.on('warning', function (warning) { + console.log(warning) throw new Error('Should not emit deprecation warning') }) diff --git a/test/test-helper.js b/test/test-helper.js index 3bb4b6c..d8e0687 100644 --- a/test/test-helper.js +++ b/test/test-helper.js @@ -1,8 +1,6 @@ //make assert a global... assert = require('assert'); -process.noDeprecation = true - //support for node@0.10.x if (typeof Promise == 'undefined') { global.Promise = require('promise-polyfill')