Skip to content

Instantly share code, notes, and snippets.

@cjgiridhar

cjgiridhar/async.js

Created Jan 17, 2013
Embed
What would you like to do?
// 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
You can’t perform that action at this time.