My question is as follows, so I understand callbacks
are functions passed as a parameter that will be executed when any statement is performed, but I often see callback
as reserved word to return parameters to a function, such as in the example below:
function run(textQuery, callback)
{
const sql = require('mssql');
var callbackDone = false;
const connectionPool = new sql.ConnectionPool(config, err => {
connectionPool.request()
.query(textQuery, (err, result) => {
sql.close();
callbackDone = true;
callback(err, result);
})
})
connectionPool.on('error', err => {
sql.close();
if(!callbackDone)
{
callback(err, null);
}
})
}
Could you explain how this works?