I am having an issue with the order of my functions, and I'm unsure why.
When hovering over the call for function_2 within the first function, VSCode gives me the result of Promise<void>, and the console outputs undefined when run (before function_2() even finishes).
Since I'm editing in VSCode, it tells me at the top when I hover over a return that it is for the request callback, so I have a general idea of what the issue is. Past that I have no idea, and it's most likely due to my lack of understanding about returns on promises and/or the true sequence of when things happen in a script.
Everything else in my code works without issue.
I have researched this quite extensively without luck (both on this site and in some general code documentation), but please let me know if there is something I missed.
I have included the general order of my functions below, and where the return calls are.
async function_1() {
const check = await function_2();
return console.log(check);
}
async function_2() {
...
if(...){
...
request(... => {
...
while(...) {
if(...) {
...
return 'result'; //<<<RETURN
}
await msg.channel.awaitMessages({
...
}).then((c) => {
if() {
...
if() {
...
return 'result'; //<<<RETURN
};
} else if {
...
return 'result'; //<<<RETURN
} else {
};
}).catch((c) => {
...
return 'result'; //<<<RETURN
});
}; //<<<end 'while'
}); //<<<end 'request'
}; //<<<end 'if'
};
If my explanation was not clear, or more code is needed, please let me know.