Skip to content

Instantly share code, notes, and snippets.

@brianc
Forked from chilts/different-pg-connect.js
Last active December 14, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianc/5090658 to your computer and use it in GitHub Desktop.
Save brianc/5090658 to your computer and use it in GitHub Desktop.
var async = require('async');
var pg = require('pg');
var connString = "postgres://postgres@localhost/template1";
// attempt 1 - all ok
pg.connect(connString, function(err, client, done) {
// this function has a .length of 3 ... therefore done is defined
console.log('1) Connected ok');
done();
// pg.end();
});
// attempt 2 - not ok
async.waterfall(
[
function(callback) {
pg.connect(connString, function(err, client, done){
callback(err, client, done);
});
},
function(client, done, callback) {
console.log('2) Connected ok');
// done is defined (but is actually the callback)
done();
callback(); // bang!
}
],
function(err) {
console.log('3');
// pg.end();
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment