如果一个请求需要很长时间才能执行,另一个选项卡将等到第一个请求完成。为什么?请解释一下。以及如何解决?这是我的代码:
var http = require("http");
var url = require("url");
http.createServer(function(request, response) {
if (url.parse(request.url).pathname == '/long')
{
function longlong()
{
var counter = 0;
var startTime = new Date().getTime();
while (new Date().getTime() < startTime + 10000)
{
counter++;
}
return counter;
}
response.writeHead(200, {"Content-Type": "text/plain"});
response.write(longlong() + '');
response.end();
}
else
{
response.writeHead(200, {"Content-Type": "text/plain"});
response.write(0 + '');
response.end();
}
}).listen(8888);