Как описывается в некоторой литературе,использование process.nextTick позволяет работать в "многопоточном". т.е между "разрывами" успевает обработать другие запросы из очереди
var http = require("http");
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
});
var time;
function sleep(milliSeconds,request, response) {
if(new Date().getTime() <time + milliSeconds)
{
// как описанно использование process.nextTick позволяет прослушивать серверу события
process.nextTick( function () {sleep(10000,request, response)});
}
else
{
sendRessult(request, response);
}
}
function sendRessult(request, response)
{
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello Worlddddd");
response.end();
console.log("stop");
}
var server=http.createServer().listen(8888);
// слушатель события
server.on('request',function(request, response) {
console.log("start");
time=new Date().getTime();
sleep(10000,request, response);
});
Запускаю почти одновременно два окна , но если бы всё было так как описывается последовательность бы была start-start-stop-stop , а не start-stop-start-stop
В чём ошибаюсь?