S
S
Stanislav2016-03-16 21:35:01
Node.js
Stanislav, 2016-03-16 21:35:01

How to pass data to a function in async using async.auto/async.apply?

Tell me if it's possible to do the following.
There is a set of functions, some of them must be executed in parallel, some sequentially, so I had to turn to async.auto. But ran into a problem

var set = {};
async.auto({
    one: async.apply(getDocument, set),
    two: ['one', async.apply(otherDataDocument, set)]
}, function(){})

function getDocument(set, callback) {
    callback(null, data);
}

function otherDataDocument(set, callback) {
    // суда необходимо передать данные из функции getDocument
}

From the example, I think everything is clear, in general, you need to accept the data received by the getDocument function in the otherDataDocument function.
How can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Yandimirkin, 2016-03-16
@ms-dred

Hold

var async = require('async');

async.auto({
    one: getDocument,
    two: ['one', otherDataDocument]
}, function () {
})

function getDocument(callback) {
    var data = "it works";
    callback(null, data);
}

function otherDataDocument(callback, result) {
    console.log(result);
    callback(null);
}

2f418692ffe34362a37b7d2a97c40223.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question