Skip to content

Instantly share code, notes, and snippets.

@luishdez
Created January 7, 2012 00:55
Show Gist options
  • Save luishdez/1573296 to your computer and use it in GitHub Desktop.
Save luishdez/1573296 to your computer and use it in GitHub Desktop.
Simple chain for node.js
exports.chainProcess = function(){
this.lastError = false;
this.lastReturn = false;
this.uWorker = false;
this.chainPosition = -1;
this.chainnedFunctions = [];
this.chainnedCatchs = [];
this.chainAlias = [];
this.onError = false;
this.execute = function(n) {
this.chainnedFunctions[n](this.lastError, this.lastReturn);
};
this.prev = function(){
this.chainPosition--;
this.execute(this.chainPosition);
};
this.next = function(){
this.chainPosition++;
this.execute(this.chainPosition);
};
this.end = function(){
this.execute(this.chainnedFunctions.length -1);
};
this.setEnd = function(){
this.chainPosition = this.chainnedFunctions.length -1;
};
this.add = function(alias, fnc){
this.chainnedFunctions.push(fnc);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment