cari

Rumah  >  Soal Jawab  >  teks badan

node.js - node async queue中这个callback是什么,为什么这里输出只有5行?

PHPzPHPz2783 hari yang lalu667

membalas semua(2)saya akan balas

  • 伊谢尔伦

    伊谢尔伦2017-04-17 14:57:30

    当然咯,因为你并发量是5,但是你的queue中并没有fork callback,所以并发量是5,没有结束也不会调新的咯。

    var async = require('async');
    var q = async.queue(function(data, callback) {
      console.log(data.name);
    // fork callback
      callback();
    }, 5);
    for(var i = 0; i < 10; ++i) {
      q.push({ name: 0 })
    }
    

    balas
    0
  • 高洛峰

    高洛峰2017-04-17 14:57:30

    var q = async.queue(function (data, callback) {
        console.log(data.name);
        callback(null)
    },5)

    少了callback

    An asynchronous function for processing a queued task, which must call its callback(err) argument when finished, with an optional error as an argument. If you want to handle errors from an inpidual task, pass a callback to q.push(). Invoked with (task, callback).

    balas
    0
  • Batalbalas