MZ Wait command in Js

I want two play two sounds one after the other, but i dont know how to do it.
I play the sounds like this.

AudioManager.playSe(Sound);
AudioManager.playSe(Sound);

This only plays it once, so i wonder if its possible to make a wait command or something. I have tried the interpreter.wait() function, but as always that doesnt work.
Why do you need two separate sounds played back-to-back? Why not merge them into a single sound file using an audio editor? This could potentially save you a bit of filesize, and would lower your risk of one of the audio files lagging—which is (or maybe was?) a thing in MV.

Waits in MV and MZ are frame-based, so they'd be unreliable for this.

If you absolutely need to have two separate sound files played in succession, you can look at JavaScript's setTimeout(). I haven't worked with audio much in MV/MZ, so I'm not sure if the base code provides any kind of listener or callback for AudioManager.playSe() completion.
Dude you are a genius. I havent thought about that.
Sadly this doesnt work for Everything. My code looks like this.

Spoiler: Code
const DoSomething= () => { Function(100, 4, 4, 7, true); // Visuals UpdateUI(); // Audio AudioManager.playSe(Sound); setTimeout(() => { Function(100, 4, 4, 7, true); // Visuals UpdateUI(); // Audio AudioManager.playSe(Sound); }, 1000); wait(1000); }; function wait(ms) { const date = Date.now(); let currentDate = null; do { currentDate = Date.now(); } while (currentDate - date < ms); }

And this is how my Event looks
1689627031978.png


I tried only using the wait function, but it doesnt play the sound twice nor does it update the Ui.
When i remove the wait function, then the show choices appear too early. And i also tried using some async await stuff, but that causes the same problem. I dont know what to do at this point.

Edit: I think it has to do with the was rpgmaker handles UI and sound. But i sadly have a hard time learning something by reading the code or watching videos.

Original thread: https://forums.rpgmakerweb.com/threads/wait-command-in-js.159381/