0
나는 아래의 코드에 문제가 : 나는 각이 코드가 서로를 차단하지 않습니다 것을 기대하고있어 내 마음에밖으로 시도 async.js는
var async = require("async");
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function hello(no){
console.log(no);
async.forEach(no,function print_list(x, callback){
console.log("I am task number : ", x);
var sleep_time = Math.floor((Math.random()*10)+1);
console.log(sleep_time);
sleep(sleep_time*1000);
},function(err){if (err){console.log(err);}});
}
list = [];
for (var a = 1000; a > 0;a--){
list.push(a);
};
hello(list);
,하지만 나는 여전히 처리됩니다 발견 동기 코드로.
어디에서 잘못 했습니까?
고맙습니다. – fitram