I am trying to understand Promises and how to write them.
const getmsg = ( ) =>{
setTimeout(()=>{
console.log('Delaying this Message');
},3000);
}
const displaymsg=()=>{
console.log('Displayed after getmsg() is executed')
}
const promise = new Promise((resolve,reject)=>{
resolve(getmsg)
})
promise
.then(response =>{
displaymsg();
console.log(response)
})
.catch(err =>{
console.log(err)
})
I have written two functions getmsg() and displaymsg(). I want the displaymsg() to be executed after getmsg(). According to my understanding i am creating a promise which executes getmsg and then displaymsg() is getting called. But it isn't happening here. Where am i doing wrong.