Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8585247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:00:45+00:00 2026-06-11T22:00:45+00:00

Using caolan’s async library for node.js, I’ve been trying to call a function that

  • 0

Using caolan’s async library for node.js, I’ve been trying to call a function that uses async.series inside another function that uses async.series, but I still can’t get the functions to run in the correct order, as detailed below:

The terminal output shows the second function being called before the first, for no apparent reason:

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]

And here’s the corresponding source code:

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:00:46+00:00Added an answer on June 11, 2026 at 10:00 pm

    After about an hour of experimentation, I got it to work properly. I simply modified the firstStep function so that it takes a callback function as a parameter, and calls the callback at the end of the firstStep function.

    var im = require('imagemagick');
    var async = require('async');
    
    var toObtain = false;
    
    
    var b;
    async.series([
    
    function (callback) {
        firstStep(callback); //the firstStep function takes a callback parameter and calls the callback when it finishes running. Now everything seems to be working as intended.
    },
    
    function (callback) {
        console.log("Starting the second step in the series");
        console.log("Value of b: " + b);
    }]);
    
    
    function firstStep(theCallback){
        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());
            theCallback();
        }]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the async library ( https://github.com/caolan/async ) on node trying to execute
I am using the node async lib - https://github.com/caolan/async#forEach and would like to iterate
I'm using async module (see https://github.com/caolan/async ) for Node.js and my question is... Why
I'm using caolan's 'async' module to open an array of filenames (in this case,
I want to iterate an array asynchronously to unblock the execution. I'm using caolan/async
I am using the excellent caolan async module for nodejs: I have this code:
Using CMake I want to check if a particular function (cv::getGaborKernel) from OpenCV library
Using Point Cloud Library on Ubuntu, I am trying to take multiple point clouds
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.