Skip to content

Instantly share code, notes, and snippets.

@cjgiridhar
Created January 17, 2013 05:13
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 cjgiridhar/4553831 to your computer and use it in GitHub Desktop.
Save cjgiridhar/4553831 to your computer and use it in GitHub Desktop.
// defining a function
var async_factorial = function(n, callback){
console.log("step1");
var fact = 1;
process.nextTick(function(){
for(var i=1; i<n; i++) {
fact = fact*i;
}
console.log("step2");
callback(fact);
});
};
// using the function
async_factorial(50, function(result){
console.log("step3");
console.log("value is:" + result);
});
console.log("Out of async");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment