I want to use async function and readline
same time. After I write to input on readline
, I want to go to the second thried (.then
). But it doesn't wait to I write to the text. I want to see phoneCode
on console but I get beforeCode
.
let phoneCode = "beforeCode";
const asenkronFonksiyon = () => {
return new Promise((resolve, reject) => {
resolve();
});
};
asenkronFonksiyon()
.then(data => {
return data;
})
.then(data => {
readline.question(`What's code?`, code => {
console.log(`Hi ${data}!`);
phoneCode = code;
readline.close();
});
return phoneCode;
})
.then(data => {
console.log("phoneCode" + phoneCode);
});