Как вы и думали, здесь необходимо использовать async / await, так как выполнение вашего dropAll
метода асинхронно.
Вы можете обратиться к этой документации , чтобы понять, как работает асинхронность Следует использовать / await.
Ваш пример может быть обновлен до следующего:
async function dropAll() {
console.log("ONE");
await db.query("SHOW tables", async (err, result) => {
await result.map(async list => {
db.query(`DROP TABLE \`${list.Tables_in_gcd_updt}\``, (err, results) => {
console.log(list.Tables_in_gcd_updt + " REMOVED");
console.log("TWO");
});
});
});
}
function getAll() {
console.log("FOUR");
}
const infiniteQuestion = async function() {
await prompt.question("What do you want to your DB project ?", async answer => {
switch (answer) {
case "drop":
await dropAll();
console.log("THREE");
getAll();
return infiniteQuestion();
case "exit":
console.log(`${answer} unknow`);
rl.close();
process.exit(0);
default:
return infiniteQuestion();
}
});
};
infiniteQuestion();