I have a function called wait which accepts time in milliseconds and returns a promise. The promise should get resolved if myEvent is fired or after some time ms whichever occurs first. Currently I am doing something like this which I don't think is the right way to do it.
async function wait(ms) {
return new Promise((res) => {
myEmitter.on('myEvent', res);
setTimeout(res, ms);
});
}
Is there a better way to do this?