Skip to content

Instantly share code, notes, and snippets.

@adrianmcli
Created January 6, 2017 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianmcli/8a2f257f3e8a8ad87586c101e9f31277 to your computer and use it in GitHub Desktop.
Save adrianmcli/8a2f257f3e8a8ad87586c101e9f31277 to your computer and use it in GitHub Desktop.
A quiz on the Javascript event loop from Daniel Parker's JavaScript with Promises
var async = true;
var xhr = new XMLHttpRequest();
xhr.open('get', 'data.json', async);
xhr.send();
// Create a three second delay (don't do this in real life)
var timestamp = Date.now() + 3000;
while (Date.now() < timestamp);
// Now that three seconds have passed,
// add a listener to the xhr.load and xhr.error events
function listener() {
console.log('greetings from listener');
}
xhr.addEventListener('load', listener);
xhr.addEventListener('error', listener);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment