M
M
MalyshevDmitry2014-01-22 19:14:59
JavaScript
MalyshevDmitry, 2014-01-22 19:14:59

How to implement passing arbitrary variables to functions within a series (node.js (async.js)) thread?

Good evening.
I need to implement the idea of ​​an approximate plan:

function taskFirst(k, v) {
    console.log(k, v);
}

function taskSecond(k, v) {
    console.log(k, v);
}

function run() {
    var g1 = "Something";
    var g2 = "Something";
    var g3 = "Something";
    var g4 = "Something";

        async.series(
            [
                taskFirst(g1, g2),
                taskSecond(g3, g4)
            ],
            function(error, result){

            }
        );
}

The question arises, how to correctly pass the variables g1, g2 ... and the async.js callback function to the taskFirst and taskSecond functions?
Simply writing taskFirst(g1, g2, callback) or taskFirst(callback, g1, g2) does not work - callback is not passed to the function in this way.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Pushkarev, 2014-01-22
@MalyshevDmitry

Something in style

function taskFirst(k, v, next) {
    console.log(k, v);
    next(null, 'ok1');
}

function taskSecond(k, v, next) {
    console.log(k, v);
    next(null, 'ok2');
}

function run() {
    var g1 = "Something";
    var g2 = "Something";
    var g3 = "Something";
    var g4 = "Something";
    async.series([
        taskFirst.bind(null, g1, g2),
        taskSecond.bind(null, g3, g4)
      ], function(error, result){

      }
    );
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question