Skip to content

Instantly share code, notes, and snippets.

@awilson28
Created November 22, 2015 17:08
Show Gist options
  • Save awilson28/ce9497779e7242df25c0 to your computer and use it in GitHub Desktop.
Save awilson28/ce9497779e7242df25c0 to your computer and use it in GitHub Desktop.
// `eventQueue` is an array that acts as a queue (first-in, first-out)
var eventQueue = [ ];
var event;
// the event loop keeps going "forever"
while (true) {
// perform a "tick"
if (eventQueue.length > 0) {
// get the next event in the queue
event = eventQueue.shift();
// now, execute the next event
try {
event();
}
catch (err) {
reportError(err);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment