Вызов async.series внутри async.series приводит к непредсказуемому выводу

Используя caolan 's асинхронная библиотека для node.js, I 'пытался вызвать функцию, которая используетasync.series внутри другой функции, которая использует async.series, но я все еще могуt получить функции для запуска в правильном порядке, как описано ниже:

Выходной терминал показывает вторую функцию, вызываемую до первой, без видимой причины:

The "sys" module is now called "util". It should have a similar interface.
Starting the second step in the series
Value of b: undefined
Invoking the function firstStep
the value of toObtain is: [object Object]

И здесь's соответствующий исходный код:

var im = require('imagemagick');
var async = require('async');

var toObtain;


var b;
async.series([

function (callback) {
    //It appears that this function is being invoked after the second function.
    //Why is this happening?
    firstStep();
    callback();
},

function (callback) {
    //Why is the output of this function being displayed BEFORE the output of the function above? It's the opposite of the order in which I'm calling the functions.
    console.log("Starting the second step in the series");
    console.log("Value of b: " + b);
}]);


function firstStep(){
    async.series([

    function (next) { // step one - call the function that sets toObtain
        im.identify('kittens.png', function (err, features) {
            if (err) throw err;
            console.log("Invoking the function firstStep");
            toObtain = features;
            //console.log(toObtain);
            b = toObtain.height;
            next(); // invoke the callback provided by async
        });
    },

    function (next) { // step two - display it
        console.log('the value of toObtain is: %s',toObtain.toString());
    }]);
}

Ответы на вопрос(1)

Ваш ответ на вопрос