Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

node.js - console.log() is "Canceled" when looping unattended

I am able to reproduce a problem I am facing in a Node project in VS Code with the following:

for (let i=0; i<50; i++) {
  let text = [ Math.random()>0.5 ? "abc" : "ABC" ];
  console.log(i);
  console.log(text);
  console.log("*")
}

If I step through manually, everything works fine.

If I let the script run at full speed, at a random iteration, the words in red "Canceled" would be printed after the first console.log prints its output. From that point onward, the second console.log(text) is skipped or outputs a blank string (I am unable to tell which).

The other two console.log() statements continue to output the correct values till the end of the loop.

The color of the "Canceled" is the same as the output of my console.error().

A sample run is as shown here where the anomaly happens after the seventh iteration:

enter image description here

I repeated the script many times, and each time the "Canceled" output happens at a different iteration. If there is a breakpoint anywhere in the script, not necessarily in the loop, the "Canceled" does not happen.

Despite the erroneous output, the values of all variables seem to be correct. In my real code, I saved the final values of text to a file and they checked out correctly.

What is happening, and is there anything to worry about?

question from:https://stackoverflow.com/questions/65914346/console-log-is-canceled-when-looping-unattended

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...