/
Async Await
Async Await
"Later doesn't happen strictly and immediately after now", for this, we have the following solution.
Every function for our Integra Framework works like this:
function functionName(){
UC_get(sqlquery,dsn,callback);
}
function callback(){
//code
}
This as been simplified as shown next, using async functions: (same function names with _async)
async function functionName(){
let resp = await UC_get_async(sqlquery,dsn);
//code
}
Await specifies that the used function must return something before continuing with the block of code that follows.
Practical example:
/**
* @name GET_MANAGEMENTS
* @desc This function gets the managements of a given client
*/
async function getManagements() {
let response = await UC_get_async("SELECT * FROM Managements WHERE client_id = " + selectedClient.id + " ORDER BY fecha DESC ", '');
return response;
}
/**
* @name MANAGEMENTS_AND_FILL
* @desc This function gets the managements of a given client and
* fills the info in the managements table
*/
async function getAndFillManagement() {
let response = await getManagements();
let managements = JSON.parse(response);
if (managements.length) {
managements = managements.map(management => {
if (management.date) {
management.date = moment(management.date).format('DD/MM/YYYY HH:mm:ss');
}
});
UC_fullTable('managementsTable', JSON.stringify(managements), 'date,agent,campaign,level1,level2,level3,coments', null, '110px', "DD/MM/YYYY HH:mm:ss", 0, "desc");
}
}