Skip to content

Instantly share code, notes, and snippets.

@catdad
Last active August 29, 2015 14:06
Show Gist options
  • Save catdad/a28f52ba38cb811f9de2 to your computer and use it in GitHub Desktop.
Save catdad/a28f52ba38cb811f9de2 to your computer and use it in GitHub Desktop.
// standardize done arguments with Continuation Passing Style
var createDoneArgs = function(args){
var doneArgs = [].slice.call(args);
doneArgs.unshift(undefined);
return doneArgs;
};
//usage
function(arg1, arg2, npcCallback) {
var that = this;
regularAsyncFunction(arg1, arg2, function(){
npcCallback.apply(that, createDoneArgs(arguments));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment