考虑这段代码:
var http = require("http");
http.createServer(function(request, response) {
for (var i = 0; i < 1000000; i++) {
console.log("Request received");
}
response.writeHead(200, {
"Content-Type": "text/plain"
});
response.write("Hello World");
response.end();
}).listen(8888, "127.0.0.1");
如果我们运行这段代码,我们也应该等待很多分钟才能得到响应。但是如果在没有 for 的情况下运行 for console.log("Request received");
,我们会得到高速响应吗?为什么?