alsotang / node-lessons

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

async.mapLimit 限制问题 #49

Open JChehe opened 9 years ago

JChehe commented 9 years ago
var superagent = require("superagent");
var async = require("async");
var cheerio = require("cheerio");

var url = require("url");

var cnodeUrl = "https://cnodejs.org/";
superagent.get(cnodeUrl)
    .end(function(err, res){
        if(err){
            // return next(err);
            console.log(err);
        }
        var $ = cheerio.load(res.text);
        var urls = [];
        $(".topic_title").each(function(index, el) {
            var that = $(el);
            var absUrl = url.resolve(cnodeUrl, that.attr("href"));
            urls.push(absUrl);
        });
        console.log("抓取地址数: "+urls.length);
        var counter = 0;
        async.mapLimit(urls, 5, function(url, callback){
            superagent.get(url)
                .end(function(err, sres){
                    var $ = cheerio.load(sres.text);
                    console.log("用户:" + $(".user_name").text() + "的积分:" + $(".big").text());
                });
        },function(err,result){
            console.log(result);
        })
    });

async.mapLimit 不是限制并发数吗? 怎么这里是限制总数的?