我在做learnyounode
教程。我在第九个教程中,我希望发送三个HTTP请求以获得结果并以相同的顺序获得这些响应。我编写了下面的代码,但是我在while循环中经常检查的变量null
,所以它停留在无限循环中。谁能告诉我为什么?
var request = require('request');
var async = require('async')
let holder = [
{
url: process.argv[2],
data: null
},
{
url: process.argv[3],
data: null
},
{
url: process.argv[4],
data: null
}
];
holder.forEach((element) => {
request(element.url,(err, response, body) => {
element.data = body;
});
});
while (true) {
if (holder[0].data != null || holder[1].data != null || holder[2].data != null)
break;
}
holder.forEach((element) => {
console.log(element.data);
})