1
My question is this, from what I understand callbacks
are functions passed as parameter that will be executed when some instruction is performed, but I often see the callback
as a reserved word to return parameters to a function, 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 to me how this works ?
Using your example, if I understand correctly, the word 'callback', in this case, is being used to complete the request for parameters required by the Handler function that was passed as a parameter to run function?
– B. Dias
In fact is passing what is callback function, is a @B.Days reference
– BrTkCa
Wow, I get it, now that it’s all clear this up pretty obvious kk, thanks for the help @Lucas Costa
– B. Dias