-
-
Save getify/cb8079dcd11e1d2080bf3f8036aee2b3 to your computer and use it in GitHub Desktop.
waitForEvent(..) -- promisified event listener
This file contains 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); | |
}); | |
} |
This may be to free up the call stack in order to have a smoother UI
Would be useful for using with async/await
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
Why inside a promise?