Using the pg
module and clients pool I need to call done()
method in order to return the client into clients pool.
Once I connect to the server, I add SQL query client’s query queue and I start handling the result asynchronously row by row in row event:
// Execute SQL query
var query = client.query("SELECT * FROM categories");
// Handle every row asynchronously
query.on('row', handleRow );
When I should call done()
method?
Should I call it once I receive the end
event and all rows are processed or I can call it immediately after I add SQL query to the client’s query queue?