alsotang / node-lessons

:closed_book:《Node.js 包教不包会》 by alsotang
16.54k stars 4.7k forks source link

使用 eventproxy 控制并发时为啥前几个获取不了comment和title #120

Closed jkgeekJack closed 6 years ago

jkgeekJack commented 7 years ago

后面的都能获取到

Topppy commented 7 years ago

注意,cnodejs.org 网站有并发连接数的限制,所以当请求发送太快的时候会导致返回值为空或报错。建议一次抓取3个主题即可。文中的40只是为了方便讲解。

可以采取增加请求间隔的措施来解决该问题。

qianlfeg1st commented 7 years ago
topicUrls.forEach(function (topicUrl, index) {
  setTimeout(function() {
    superagent.get(topicUrl)
      .end(function (err, sres) {
          ep.emit('topic_html', [topicUrl, sres.text]);
      });
  }, 300 * index);
});

这样就行了

freedomDR commented 6 years ago

学习了