I would like to wait some time, execute one method and go on. Some one similar to:
setTimeout(()=> someMethod());
The problem is that the process goes on before the method is executed.
Could you help me?
I would like to wait some time, execute one method and go on. Some one similar to:
setTimeout(()=> someMethod());
The problem is that the process goes on before the method is executed.
Could you help me?
You can wait on a promise as followed:
const wait5s = () => {
return new Promise(resolve => {
setTimeout(() => resolve(), 5000)
})
}
async function myFunc() {
await wait5s()
// Call you method here
console.log('Hello World!')
}
myFunc()
Hope that answers your question.