Skip to content

Instantly share code, notes, and snippets.

@jakemcgraw
Created May 27, 2011 17:45
Show Gist options
  • Save jakemcgraw/995762 to your computer and use it in GitHub Desktop.
Save jakemcgraw/995762 to your computer and use it in GitHub Desktop.
How to interrupt a timeout
var pollInterval = 10000,
pollTimeout = null;
function pollSpots() {
printDXSpots();
pollTimeout = window.setTimeout(pollSpots, pollInterval);
}
// ... later ...
function forcePollSpots() {
if (pollTimeout) {
window.clearTimeout(pollTimeout);
}
printDXSpots();
pollTimeout = window.setTimeout(pollSpots, pollInterval);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment