Hello ,
I want to write a programme which comprises of 2 function func1 and func2 , I want it in such a way that function 1 should wait for 3 seconds for user to input any value. Within 3 second if input is given then it should be displayed and func2 executes after that . And if no input is given within 3 seconds then func2 executes directly. It is sort of required to use async and await . Below is the source code which I tried
const prompt = require('prompt-sync')();
function firstMessage(){
var d ;
//timeout function for delaying request
setTimeout( async function(){
d= await inpp();
}, 3000);
console.log(d);
}
function secondMessage() {
console.log("2");
}
firstMessage();
secondMessage();
async function inpp()
{
var z = prompt("Enter value to pass");
return z ;
}
However , this function is printing value of d & 2 and then asking for value . Can anyone please tell me where am I wrong and help me modify the code.
Thank You