Skip to content

Instantly share code, notes, and snippets.

@acnalesso
Created December 1, 2014 19:30
Show Gist options
  • Save acnalesso/d24641866e84bbf4f7c5 to your computer and use it in GitHub Desktop.
Save acnalesso/d24641866e84bbf4f7c5 to your computer and use it in GitHub Desktop.
Backburner run method
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