qendu
qendu

Reputation: 289

Node.js async.queue doesn't work

I have this very simple program and the output should be "foo" and then "baz", but for some reason "baz" isn't printed on the screen. What mistake am I making?

var async = require('async');

var q = async.queue(function (task, callback) {
    console.log(task.message);
}, 1);

q.push({ message : "foo" }, function (err) {});
q.push({ message : "baz" }, function (err) {});

Upvotes: 1

Views: 2675

Answers (2)

Martin
Martin

Reputation: 755

You just forgott the

callback()

Try this it works for me:

var async = require('async');

var q = async.queue(function (task, callback) {
    console.log(task.message);
    callback();
}, 1);

q.push({ message : "foo" }, function (err) {});
q.push({ message : "baz" }, function (err) {});

Upvotes: 1

freakish
freakish

Reputation: 56527

You have to call callback in queue:

var q = async.queue(function (task, callback) {
    console.log(task.message);
    callback( );
}, 1);

This way it informs the queue, that it finished the task and the queue can jump to another one.

Upvotes: 4

Related Questions