I have a function that needs to keep running back and forth between the if and else till it is complete.
My code:
const mainFunc = (fn) => {
return async (query_name, ...args) => {
const result = await axios_Func(query_name);
try {
return fn(result, ...args);
} catch (e) {
console.log(e);
}
};
};
const createFunc = mainFunc((result, table_id) => {
(async () => {
let dev = await getTabs({ query: tables(123) });
let prod = await getTabs({ query: tables(321) });
result.data.forEach((d) => {
if (d.connector == null) {
axios_Func({ graphQL query }).then((response) => {
if (response.data.errors) {
// rerun function on errors
} else console.log(JSON.stringify(response.data, null, 4));
});
} else {
if (d.name in dev) {
axios_DevFunc({ graphQL query }).then((response) => {
console.log(`created from dev`);
console.log(JSON.stringify(response.data, null, 4));
});
} else {
axios_ProdFunc({ graphQL query }).then((response) => {
.then((res) => res)
.then((x) => {
//repeat Dev Function after axios_ProdFunc is finished
axios_DevFunc({ graphQL query }).then((response) => {
console.log(`created from dev`);
console.log(JSON.stringify(response.data, null, 4));
});
});
}
}
});
})();
});
My createFunc starts with going through the first if (d.connector == null). If that is true then run the axios_Func. If it returns errors then I would like to rerun the function of the errors.
- I am unsure how to rerun a function on the errors. THese errors usually crop up sometimes but when manually rerun, they work.
After this going into the else, I have an if inside that to check if name is in the dev object declared earlier in the function. If that is true then run the axios_DevFunc function. Else run the axios_ProdFunc first.
- After that is complete, I want to be able to run the
axios_DevFuncagain.
The issue is, my code is not giving me any errors but is not running in order. Everything just seems to be running at once haphazardly. How do I get it to run in the way I have mentioned above?