Skip to content

Instantly share code, notes, and snippets.

@getify
Created June 2, 2018 04:09
Show Gist options
  • Save getify/cb8079dcd11e1d2080bf3f8036aee2b3 to your computer and use it in GitHub Desktop.
Save getify/cb8079dcd11e1d2080bf3f8036aee2b3 to your computer and use it in GitHub Desktop.
waitForEvent(..) -- promisified event listener
function waitForEvent(elem,evtName) {
return new Promise(function c(resolve){
elem.addEventListener(evtName,function onEvent(evt){
elem.removeEventListener(evtName,onEvent,false);
resolve(evt);
},false);
});
}
@LoicMahieu
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment