If you’re not in an async context and just want to delay the next step, a classic setTimeout()
still does the job:
console.log('Start');
setTimeout(() => {
console.log('This runs after 2 seconds');
}, 2000);
console.log('End');
It won’t pause execution inline like sleep()
, it schedules the next part to happen later. So anything after setTimeout runs immediately unless wrapped in the callback.