So, basically, I want to do is:
- Get an Event from an event listener,
- handling that event,
- waiting for it to finish,
- and then pass to another in the queue,
so if I get like 15 an event 15 times, I don't want to be handled all at the same time but more like event handle-await seconds event. I've tried like this to have one printed, then 5 seconds, then two with multiple clicks but what I've got was a lot of "one" at the same time and then a cascade of "two."
document.addEventListener("click", async function(event) {
if (!event.target.matches(".button-name"));
console.log("one");
await sleep(5000);
console.log("two");
event.preventDefault();
}, );
async function sleep(milliseconds) {
return new Promise((resolve) = \ > setTimeout(resolve, milliseconds));
}