I have the following snippet:
let zxcv = () => new Promise((resolve, reject) => {
setTimeout(() => {
console.log(4)
}, 1000)
})
async function jk(){
await zxcv()
console.log(6)
}
jk()
When I run this snippet, it waits for a second, then logs "4", then ends. "6" never gets logged.
Why?
You never resolved your promise in zxcv
:
let zxcv = () => new Promise((resolve, reject) => {
setTimeout(() => {
console.log(4)
resolve()
}, 1000)
})
Otherwise the promise will hang indefinitely!