Node.js tutorial을 따르고 있고 "차단 및 차단 해제"섹션에 차단 관련 문제를 설명하는 코드가 있습니다.왜이 코드 블록이 Node.js에 있지 않습니까?
function start() {
console.log("Request handler 'start' was called.");
function sleep(milliSeconds) {
var startTime = new Date().getTime();
while (new Date().getTime() < startTime + milliSeconds);
}
sleep(10000);
return "Hello Start";
}
function upload() {
console.log("Request handler 'upload' was called.");
return "Hello Upload";
}
exports.start = start;
exports.upload = upload;
하는 index.js
var server = require("./server");
var router = require("./router");
var requestHandlers = require("./requestHandlers");
var handle = {}
handle["/"] = requestHandlers.start;
handle["/start"] = requestHandlers.start;
handle["/upload"] = requestHandlers.upload;
server.start(router.route, handle);
나는 http://localhost:8888/start 및 http://localhost:8888/upload를로드했습니다. 그들은 차단 때문에로드하는 데 10 초가 걸릴 것으로 예상되지만 둘 다 즉시로드됩니다. 왜? node.js에서 sleep() 함수를 직접 실행하면 차단되지만 웹 브라우저에서는 차단되지 않습니다. 이것은 더 이상 어떤 이유로 다루어 져야 할 문제가 아닌가?
로컬 컴퓨터의 파일에 연결했습니다. 코드 자체를 게시하는 것이 좋습니다. – Dennis
링크를 수정하고 코드도 포함 시켰습니다. – neuromancer
코드가 작동해야합니다. 어떻게'start' 함수를 호출합니까? – stewe