Skip to content

Commit 76c1000

Browse files
committed
Add event-emitters back
1 parent 0ce8a6c commit 76c1000

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

lib/client.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ Client.prototype.query = function (config, values, callback) {
374374
}
375375
} else {
376376
query = new Query(config, values, callback)
377-
query._deprecateListeners()
378377
result = query
379378
}
380379

lib/native/client.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,9 @@ Client.prototype.query = function(config, values, callback) {
131131
}
132132

133133
var query = new NativeQuery(config, values, callback);
134-
var result = query.callback ? query : new global.Promise(function(resolve, reject) {
135-
query.on('end', resolve);
136-
query.on('error', reject);
137-
});
138-
139134
this._queryQueue.push(query);
140135
this._pulseQueryQueue();
141-
return result;
136+
return query;
142137
};
143138

144139
//disconnect from the backend server

lib/native/query.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ NativeQuery.prototype.handleError = function(err) {
6767
self.state = 'error';
6868
};
6969

70+
NativeQuery.prototype.then = function(onSuccess, onFailure) {
71+
return this._getPromise().then(onSuccess, onFailure);
72+
};
73+
74+
NativeQuery.prototype.catch = function(callback) {
75+
return this._getPromise().catch(callback);
76+
};
77+
78+
NativeQuery.prototype._getPromise = function() {
79+
if (this._promise) return this._promise;
80+
this._promise = new Promise(function(resolve, reject) {
81+
this.once('end', resolve);
82+
this.once('error', reject);
83+
}.bind(this));
84+
return this._promise;
85+
};
86+
7087
NativeQuery.prototype.submit = function(client) {
7188
this.state = 'running';
7289
var self = this;

lib/query.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ Query.prototype._getPromise = function() {
7070
return this._promise;
7171
};
7272

73-
Query.prototype._deprecateListeners = function() {
74-
}
75-
7673
//associates row metadata from the supplied
7774
//message with this query object
7875
//metadata used when parsing row results

0 commit comments

Comments
 (0)