-
-
Save getify/cb8079dcd11e1d2080bf3f8036aee2b3 to your computer and use it in GitHub Desktop.
waitForEvent(..) -- promisified event listener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function waitForEvent(elem,evtName) { | |
return new Promise(function c(resolve){ | |
elem.addEventListener(evtName,function onEvent(evt){ | |
elem.removeEventListener(evtName,onEvent,false); | |
resolve(evt); | |
},false); | |
}); | |
} |
Don't use async/await on this...
Sindre already did it :)
https://github.com/sindresorhus/p-event
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would be useful for using with
async/await