Skip to content

Instantly share code, notes, and snippets.

@mendes5
Created March 14, 2018 17:31
Show Gist options
  • Select an option

  • Save mendes5/400468468b47ce8794894c07a7b7b444 to your computer and use it in GitHub Desktop.

Select an option

Save mendes5/400468468b47ce8794894c07a7b7b444 to your computer and use it in GitHub Desktop.
Provides `clearAllTimeouts()` and `clearAllIntervals()`.
(()=>{
const timeout = window.setTimeout, interval = window.setInterval
let intervals = [], timeouts = []
window.setTimeout = (cb, tm, rv) => (timeouts.push(rv = timeout(cb, tm)), rv)
window.setInterval = (cb, tm, rv) => (intervals.push(rv = interval(cb, tm)), rv)
window.clearAllTimeouts = () => {timeouts.map(e => clearTimeout(e)); timeouts = []}
window.clearAllIntervals = () => {intervals.map(e => clearInterval(e)); intervals = []}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment