Add event-emitters back

This commit is contained in:
Brian M. Carlson 2017-06-16 16:11:25 -05:00 committed by Brian C
parent 0ce8a6c675
commit 76c1000567
4 changed files with 18 additions and 10 deletions

View File

@ -374,7 +374,6 @@ Client.prototype.query = function (config, values, callback) {
}
} else {
query = new Query(config, values, callback)
query._deprecateListeners()
result = query
}

View File

@ -131,14 +131,9 @@ Client.prototype.query = function(config, values, callback) {
}
var query = new NativeQuery(config, values, callback);
var result = query.callback ? query : new global.Promise(function(resolve, reject) {
query.on('end', resolve);
query.on('error', reject);
});
this._queryQueue.push(query);
this._pulseQueryQueue();
return result;
return query;
};
//disconnect from the backend server

View File

@ -67,6 +67,23 @@ NativeQuery.prototype.handleError = function(err) {
self.state = 'error';
};
NativeQuery.prototype.then = function(onSuccess, onFailure) {
return this._getPromise().then(onSuccess, onFailure);
};
NativeQuery.prototype.catch = function(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);
}.bind(this));
return this._promise;
};
NativeQuery.prototype.submit = function(client) {
this.state = 'running';
var self = this;

View File

@ -70,9 +70,6 @@ Query.prototype._getPromise = function() {
return this._promise;
};
Query.prototype._deprecateListeners = function() {
}
//associates row metadata from the supplied
//message with this query object
//metadata used when parsing row results