modified callback nesting to ensure test is called after all setup is complete

This commit is contained in:
brianc 2010-10-23 21:16:21 -05:00
parent 3edb02aa67
commit a5fba7515e
2 changed files with 13 additions and 13 deletions

View File

@ -2,6 +2,9 @@ var helper = require(__dirname + '/test-helper');
http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
helper.connect(function(con) {
con.on('message', function(msg) {
console.log(msg.name);
});
con.parse({
text: 'select * from ids'
@ -9,26 +12,24 @@ helper.connect(function(con) {
con.flush();
con.once('parseComplete', function() {
console.log('parseComplete');
con.bind();
con.flush();
});
con.once('bindComplete', function() {
console.log('bindComplete');
con.execute();
con.flush();
});
con.on('dataRow', function(msg) {
sys.debug("got row from pepared query");
con.once('dataRow', function(msg) {
console.log("row: " + sys.inspect(msg));
});
con.on('commandComplete', function() {
con.once('commandComplete', function() {
con.sync();
});
con.on('readyForQuery', function() {
con.once('readyForQuery', function() {
con.end();
});

View File

@ -22,14 +22,13 @@ var connect = function(callback) {
authConnect(function(con) {
con.once('readyForQuery', function() {
con.query('create temp table ids(id integer)');
con.once('readyForQuery', function() {
con.query('insert into ids(id) values(1); insert into ids(id) values(2);');
con.once('readyForQuery', function() {
callback(con);
});
});
});
con.once('readyForQuery', function() {
con.query('insert into ids(id) values(1); insert into ids(id) values(2);');
});
con.once('readyForQuery', function() {
callback(con);
});
});
};