Skip to content

Instantly share code, notes, and snippets.

@xhinking
Created November 10, 2016 08:55
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 xhinking/169545b3724340093f4fd6bd9e3bf39e to your computer and use it in GitHub Desktop.
Save xhinking/169545b3724340093f4fd6bd9e3bf39e to your computer and use it in GitHub Desktop.
function timeoutify(fn, delay) {
var intv = setTimeout(function() {
intv = null
fn(new Error("Timeout!"))
}, delay)
return function() {
if (intv) {
clearTimeout(intv)
fn.apply(this, arguments)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment