Answer the question
In order to leave comments, you need to log in
Why is the code not being executed
Good day.
Lately, I've been breaking records for writing in the NodeJS hub. So to speak, I am saturated with this engine more and more.
Having achieved some success, I again ran into the problem of the cause of which I don’t fully understand and, accordingly, I can’t solve:
Code
...
for(var b=0, len = fields.length;b<len;b++){
jsdom.env({
html: './dummy.html',
src: [jquery],
done: function (errors, window) {
console.log('aa');
}
})
len++;
}
Answer the question
In order to leave comments, you need to log in
Surely this function, like (almost) everything in the world of Node.JS, works asynchronously. And since your cycle is infinite, it simply does not have processor time left to do its job.
But this is just a guess.
The answer is quite simple - the fact is that your code is not called in principle.
When you execute a function in the CURRENT context, then the node pipeline (V8) is busy executing your function - say for example - function foo()
You are trying to create a jsdom object BUT the result of the env method is asynchronous, so it will be added to the stack of future calls, BUT i.e. to. in the current context, function foo has not yet completed, the scheduler cannot move on to another job.
For example, Mozilla Rhino doesn't have this problem thanks to Java, but in V8 the threading model is exclusively single-threaded within a context.
Solution: try calling each iteration via setTimeout or process.nextTick (although of course this method will be deprecated soon) then you will get a heavily loaded pipeline, but you will still have asynchronous events.
PS If the call stack fills up infinitely with more than 50000 returns, the node will most likely crash, so don't forget to control the growth of the queue manually.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question