I am somewhat new to the latest Javascript syntax and I am building an application that relies on it. I was able to create an async function that incorporates the fetch command to go to my Java back-end and retreive data. Though, I want to have the ability to set a timeout value of like 3 minutes, and if it goes over that to display a message. I somewhat know how to do it in plain vanilla javascript but I can't seem to get it for the async function. I read some examples online and documentation but still can't figure it out.
Async Function:
async function deleteGP(code){
const csrfToken = $("meta[name='_csrf']").attr("content");
console.log(csrfToken);
const result = await fetch ('/ajax/deleteGrouping' , {
method: "POST",
body: JSON.stringify ({
dtoTiername: code
}),
headers : {
"X-CSRF-Token": csrfToken,
"Content-type": "application/json; charset=UTF-8",
'Accept': 'application/json'
},
});
const data = await result.json();
console.log(data);
if(data){
$('#overlay').hide();
$('#successModal').modal();
$('#successModal').on('hidden.bs.modal', function () {
location.reload(true);
});
}else {
$('#overlay').hide();
$('#failModal').modal();
$('#failModal').on('hidden.bs.modal', function () {
location.reload(true);
});
}
}