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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -