I have some javascript code that I'm trying to understand. I have a function that returns a Promise, and within one of the then
blocks I have an axios.post
(from axios library). When this function runs, in the console I see "finish here", but I never see "post complete". I assume that's because the function finishes before the axios.post response returns? Is that correct? What would I need to do if I also wanted "post complete" to show in the console?
function X () {
return new Promise((resolve, reject) => {
if (x) {
...
resolve();
} else {
...
reject();
}
}).then(() => {
axios.post(
url,
data
).then((response) => {
...
console.log("post complete");
});
}).then(() => {
...
console.log("finish here");
});
}