Created
December 1, 2014 19:30
-
-
Save acnalesso/d24641866e84bbf4f7c5 to your computer and use it in GitHub Desktop.
Backburner run method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run: function(target, method, /* options, arguments */) { | |
var onError = getOnError(this.options); | |
this.begin(); | |
if (!method) { | |
method = target; | |
target = null; | |
} | |
if (isString(method)){ | |
method = target[method]; | |
} | |
var args = slice.call(arguments, 2); | |
var didFinally = false; | |
if (onError){ | |
try { | |
return method.apply(target, args); | |
} catch(error) { | |
onError(error); | |
} finally { | |
if (!didFinally) { | |
didFinally = true; | |
this.end(); | |
} | |
} | |
} else { | |
try { | |
return method.apply(target, args); | |
} finally { | |
if (!didFinally) { | |
didFinally = true; | |
this.end(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment