Note: this is not a replicated post for those about settimeout, the key answer here is browser design options.
I am starting study node.js:
A simple example to test async:
var http=require('http');
http.createServer(
function(request, response){
response.writeHead(200);
response.write("Hello, dog is running");
setTimeout(
function(){
response.write("Dog is done");
response.end();
},
10000
);
}
).listen(8080);
console.log("Listen on port 8080")
One interesting thing is its behavior is differernt when in command lind with curl and in browser:
In Ubuntu 12.10, I use curl localhost:8080 in two consoles, they response in almost same 10 sends.
However, I open two browsers, make the request at almost same time, but the whole procedure took me 20 seconds?
thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…