javascript - No result from callback function in Node.js -
javascript - No result from callback function in Node.js -
i want execute callback function
function recurring_end() { var sql= "select `bookmarks`.`id`,`bookmarks`.`bookmark_url` url bookmarks limit 0, 10"; connection.query(sql, function(err,bookmarks) { for(var = 0; i< bookmarks.length; i++){ (function(i) { parsearticle(i,function(err,result){ console.log("result "+json.stringify(result)); newparseartilce(result,function() { console.log("new parse artilce " +i); }); }); })(i); } }); } function newparseartilce(i,callback){ console.log("new article number is "+i); } function parsearticle(i,callback) { console.log("parse article number " +i); homecoming i; };
this code. executing parsearticle function first , want pass result newparsearticle not getting result in parseartilce.
any idea, why causing problem
thanks
because parsearticle
synchronous. should be:
function parsearticle(i, callback) { console.log("parse article number " +i); callback(null, i); // executes callback, null err , result }
also lastly console.log
won't executed. should this:
function newparseartilce(i,callback){ console.log("new article number is "+i); callback(); // executes callback }
javascript node.js
Comments
Post a Comment