In following helper method I am trying to check current omni agent status, before updating it to new one.
handleStatus: function(cmp) {
let action = cmp.get("c.checkCurrentTimeIsWithinBusinessHours");
action.setCallback(this, function(response) {
let state = response.getState();
if (state === "SUCCESS") {
setTimeout((() => {
let omniAPI = cmp.find("omniToolkit");
function f(){
//checking status
omniAPI.getServicePresenceStatusId().then(function(result) {
console.log('Status Id is: ' + result.statusApiName);
cmp.set('v.isworking', true);
}).catch(function(error) {
console.log('Status Id is: offline');
cmp.set('v.isworking', false);
});
}
//changing status
if (response.getReturnValue().isWorking && !cmp.get('v.isworking')){
console.log('Setting online');
omniAPI.setServicePresenceStatus({statusId: response.getReturnValue().statusId.toString()}).then(function(result) {
}).catch(function(error) {
console.log(error);
});
} else if (!response.getReturnValue().isWorking && cmp.get('v.isworking')){
console.log('Setting offline');
cmp.set('v.isworking', false);
omniAPI.logout();
}
}), 1000)
} else {
console.log(response.getError());
}
});
$A.enqueueAction(action);
}
As I understand async/await does not work in aura component and I dont belive that adding another settimeout to the 2nd function is a best practice.
So basically changing status function finishes 1st and checking status – 2nd. Is there any way to set order of execution so that checking status finish before checking status?
Thanks in advance.