I have this function to play audio using a given source and it works fine:
function sfxPlay(source) {
let sfxAudio = new Audio(`${source}`);
sfxAudio.crossOrigin = "anonymous";
sfxAudio.play();
return new Promise((resolve) => {
sfxAudio.addEventListener("ended", function () {
sfxAudio.currentTime = 0;
resolve();
});
});
}
I will use it inside an async function like this:
await sfxPlay(source.mp3);
The question is what if I want to use the function without await? Does this make any errors if later I use it with await again... what happens to that promise when we don't await for it?!
EDIT: I mean if we have the function like this inside function A:
sfxPlay(source.mp3);
Is it acceptable to use it inside function B like this?
await sfxPlay(source.mp3);