no it probably won't be ok. if one of those queries fails the queries after it will still run. you'll need to there was a bug at one point that kept this code from working, there's been no update on the post tho. you could do the promise.all() if you want to stop running queries if one of them fails or you can wrap them all up in a promise w resolve/reject tokens passed to onSuccess/onFailure.
async function processClients() {
loading.setValue(true)
let querylist = [];
querylist.push(fetchClients.trigger());
querylist.push(extractRealClients.trigger());
querylist.push(calculateStatistics.trigger());
querylist.push(fetchClientsPrevYear.trigger());
querylist.push(extractRealClientsPrevYear.trigger());
querylist.push(calculateStatisticsPrevYear.trigger());
querylist.push(calculatePercentages.trigger());
querylist.push(fetchClientDetails1Year.trigger());
querylist.push(extractThreeLastMonths.trigger());
querylist.push(statisticsThreePrevMonths.trigger());
Promise.all(querylist).then(() => {
console.log("All operations completed successfully."));
}.catch (error) {
console.error("An error occurred during the process:", error);
}.finally {
loading.setValue(false)
}
function triggerQuery(query) {
return new Promise((resolve, reject) => {
query.trigger({
onSuccess: resolve,
onFailure: reject
})
})
}
async function processClients() {
loading.setValue(true)
try {
await triggerQuery(fetchClients);
await triggerQuery(extractRealClients);
await triggerQuery(calculateStatistics);
await triggerQuery(fetchClientsPrevYear);
await triggerQuery(extractRealClientsPrevYear);
await triggerQuery(calculateStatisticsPrevYear);
await triggerQuery(calculatePercentages);
await triggerQuery(fetchClientDetails1Year);
await triggerQuery(extractThreeLastMonths);
await triggerQuery(statisticsThreePrevMonths);
console.log("All operations completed successfully.");
} catch (error) {
console.error("An error occurred during the process:", error);
} finally {
loading.setValue(false)
}
}
// Make sure to call the function to execute the async process.
processClients();