Fix deprecation warnings in native driver

This commit is contained in:
Brian Carlson 2017-06-20 09:17:27 -05:00 committed by Brian C
parent 842803c7ef
commit e4469340ae
4 changed files with 22 additions and 11 deletions

View File

@ -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

View File

@ -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;
};

View File

@ -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')
})

View File

@ -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')