javascript - looping in a node.js callback function -


can run loop (while, for, dowhile etc) in callback function. here sample code :

var execute = function (data,callback)  {     //do data     callback(); }  execute (data,function(error,returndataarray) {     var boo = true;     while(boo)     {         //do returndataarray         if (returndataarray.length == 10)              boo=false;     } }); 

now, doubt is, main node.js thread wait until above while loop executed?

your main thread blocked looping occuring inside callback function. that's because callback functions delayed until completion, , then, they're pushed javascript event loop , executed once thread free. in simpler word, in node (and javascript) happen in single thread (normal execution, callback, timeouts, etc).

the way execute function thread javascript manually pushing thread. in browser that'll web worker, , on node cluster.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -