readability refactoring

This commit is contained in:
brianc 2011-02-04 20:03:41 -06:00
parent 84e452e221
commit 0732ee215f

View File

@ -66,31 +66,24 @@ p.connect = function() {
con.password(md5password);
});
//hook up query handling events to connection
//after the connection initially becomes ready for queries
con.once('readyForQuery', function() {
//hook up query handling events to connection
//after the connection initially becomes ready for queries
var ready = function() {
if(self.activeQuery) {
self.activeQuery.handleReadyForQuery();
}
self.readyForQuery = true;
this.activeQuery = null;
self.pulseQueryQueue();
};
//delegate row descript to active query
con.on('rowDescription', function(msg) {
self.activeQuery.handleRowDescription(msg);
});
//delegate datarow to active query
con.on('dataRow', function(msg) {
self.activeQuery.handleDataRow(msg);
});
//TODO should query gain access to connection?
con.on('portalSuspended', function(msg) {
self.activeQuery.getRows(con);
});
con.on('commandComplete', function(msg) {
//delegate command complete to query
self.activeQuery.handleCommandComplete(msg);
//need to sync after each command complete of a prepared statement
if(self.activeQuery.isPreparedStatement) {
@ -98,12 +91,15 @@ p.connect = function() {
}
});
con.on('readyForQuery', function() {
ready();
});
ready();
});
con.on('readyForQuery', function() {
if(self.activeQuery) {
self.activeQuery.handleReadyForQuery();
}
this.activeQuery = null;
self.readyForQuery = true;
self.pulseQueryQueue();
});
con.on('error', function(error) {
@ -122,12 +118,11 @@ p.connect = function() {
p.pulseQueryQueue = function() {
if(this.readyForQuery===true) {
if(this.queryQueue.length > 0) {
this.activeQuery = this.queryQueue.shift();
if(this.activeQuery) {
this.readyForQuery = false;
var query = this.queryQueue.shift();
this.activeQuery = query;
this.hasExecuted = true;
query.submit(this.connection);
this.activeQuery.submit(this.connection);
} else if(this.hasExecuted) {
this.activeQuery = null;
this.emit('drain')