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 7821677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:43:20+00:00 2026-06-02T07:43:20+00:00

I am having problem with calling the generated functions in serial. I am using

  • 0

I am having problem with calling the generated functions in serial. I am using the async library and the code seems to work when there is no deep callback calling needed. When I add the real scenario it throws errors.

Here is the example which works, returns the array of 0 to 4:

Scrape.prototype.generatePageFunctions = function() {
  var functionList = new Array(), self = this;

  for (var i = 0; i < this.pageSet; i++) {
    (function(i) {
      functionList.push(function(cb) {
        // Inner functions which will be called in seriers
        var timeoutTime = parseInt(Math.random() * 5000 + 3000, 10);

        setTimeout(function() {
          self.setIndex(i);
          //self.getSite(function)

          cb(null, i);
        }, timeoutTime);
      });
    })(i);
  }
  return functionList;
}

Scrape.prototype.run = function() {
  var functionList = this.generatePageFunctions();

  async.series(functionList, function(err, results) {
    console.log('Job is completed ');
    console.log(results);
  });
}

Now adding the real scenario like downloading the site and then put in callback:

Scrape.prototype.generatePageFunctions = function() {
  var functionList = new Array(), self = this;

  for (var i = 0; i < this.pageSet; i++) {
    (function(i) {
      functionList.push(function(cb) {
        // Inner functions which will be called in seriers
        var timeoutTime = parseInt(Math.random() * 5000 + 3000, 10);

        setTimeout(function() {
          self.setIndex(i);
          self.getSite(function(result) {
            // Async callback to pass the data
            cb(null, result);
          });
        }, timeoutTime);
      });
    })(i);
  }
  return functionList;
}

Error is like this, even if passing instead of result iterator variable i:

/home/risto/scrape/node_modules/async/lib/async.js:185
            iterator(x.value, function (err, v) {
                      ^
TypeError: Cannot read property 'value' of undefined
    at /home/risto/scrape/node_modules/async/lib/async.js:185:23
    at /home/risto/scrape/node_modules/async/lib/async.js:108:13
    at /home/risto/scrape/node_modules/async/lib/async.js:119:25
    at /home/risto/scrape/node_modules/async/lib/async.js:187:17
    at /home/risto/scrape/node_modules/async/lib/async.js:491:34
    at /home/risto/scrape/scraper/scrape.js:114:13
    at /home/risto/scrape/scraper/scrape.js:64:16
    at Object.<anonymous> (/home/risto/scrape/scraper/engines/google.js:58:12)
    at Function.each (/home/risto/scrape/node_modules/cheerio/lib/api/utils.js:133:19)
    at [object Object].each (/home/risto/scrape/node_modules/cheerio/lib/api/traversing.js:69:12)

// Edit

Only result which gets added into the complete callback is the first one, other functions are never called.
Also for information the functions return object literals if that does matter.

  • 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-02T07:43:21+00:00Added an answer on June 2, 2026 at 7:43 am

    There is nothing wrong with your code. Creating a simple testcase shows that.

    I created a mock:

    Scrape = function() {
      this.pageSet = 5;
    }
    
    Scrape.prototype.setIndex = function() {
    }
    
    Scrape.prototype.getSite = function(cb) {
      cb('works');
    }
    

    and calling the run method it outputs the expected:

    [ 'works', 'works', 'works', 'works', 'works' ]
    

    So the problem is somewhere else. Have you tried to check the functionList variable in your run method?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

guys I'm a new iOS developer, I'm having a problem when calling soap functions
Im having a problem with using a variable as the class name when calling
I am having a problem calling a model property from my view. I may
I'm having a problem with calling a function in a different class in QT
I am having a problem with Vlad on windows. After calling rake vlad:deploy I
I am having problem in getting reference of Ajax control extender using $find() or
I'm having problem restricting a query in mdx, using except function at where clause.
I am having a problem with calling a ext function in odata4j in android
I am having a problem while calling overloaded C# function through jquery post method.
I'm having a problem in calling a function that returns a result, from another

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.