Skip to content

Instantly share code, notes, and snippets.

@xhinking
Created November 10, 2016 09:12
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/6875e03e1198aecef42d0ee087e4a8ee to your computer and use it in GitHub Desktop.
Save xhinking/6875e03e1198aecef42d0ee087e4a8ee to your computer and use it in GitHub Desktop.
function asyncify(fn) {
var orig_fn = fn,
intv = setTimeout(function() {
intv = null
if (fn) fn()
}, 0)
fn = null
return function() {
if (intv) {
fn = orig_fn.bind.apply(orig_fn, [this].concat([].slice.call(arguments)))
} else {
orig_fn.apply(this, arguments)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment