Search code examples
node-postgres

Is done() required if node-postgres .connect() returns with an error?


From the docs it sounds like err is not null if there was a problem getting a client from the pool. If that's the case, does it mean done() doesn't need to be called?

pg.connect(connString, function(err, client, done){
    if (err) { done(); return err; }

    ...
});

or

pg.connect(connString, function(err, client, done){
    if (err) { return err; }

    ...
});

Solution

  • You only call done() when connect() was successful, i.e. err is null or undefined.

    So the second example is correct.