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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:08:37+00:00 2026-05-23T05:08:37+00:00

I have a list of types: [type1, type2, type3], on which I loop. For

  • 0

I have a list of types: [“type1”, “type2, “type3”], on which I loop. For each type:
– create / execute a query to get the items of a the current type
– run another function when the query if done ( on(‘end’) ).

 for ( var i=0; i<types.length; i++ ){
    type = types[i];
    value = "test";
    ...

    // ADD ITEM: QUERY
    var query = client.query(...); // QUERY ITEMS OF A THE CURRENT TYPE

    // ADD ITEM: ERROR CHECKING
    query.on("error", function (err) {
      ...
    });

    with ({ t: type, v: value }) {  // I HAD TO DO THAT SO THAT ALL THE TYPES ARE TAKEN INTO ACCOUNT
      query.on('end', function() {
        my_function(t, v);
      });
    }
  }

my_function is like:

function my_function(type, value){
   console.log(type + ',' + value);  // CORRECT (I CAN SEE ALL THE TYPES BEEING LISTED)

   // QUERY OTHER STUFF BASED ON THE VALUE OF "type"
   var query = client.query(...);

   // MAIN STUFF
   query.on('row', function(row){
      console.log(type + ',' + value);  // THIS DOES NOT WORK ANYMORE... ONLY THE LAST TYPE IS TAKEN INTO ACCOUNT WHERE I EXPECT TO GET THIS MESSAGE FOR EACH TYPES.
     ...
   }

   // FINALIZE
   query.on('end', function(){
      ...
   }      
}

I guess this is linked to asynchronous process… but cannot figure out where the error is.

UPDATE

I have updated my loop so it looks like:

 for ( var i=0; i<types.length; i++ ){
    type = types[i];
    value = "test";
    ...

    // ADD ITEM: QUERY
    var query = client.query(...); // QUERY ITEMS OF A THE CURRENT TYPE

    // ADD ITEM: ERROR CHECKING
    query.on("error", function (err) {
      ...
    });

    // MAIN STUFF GOES HERE
    (function(t, v) { query.on("end", function() {
      console.log(t + ',' + v); // OK, I CAN SEE THIS DISPLAYED FOR EACH TYPE
      my_function(t, v);
    }); })(type, value);
  }

I modified my_function so it looks like:

function my_function(type, value){
   console.log(type + ',' + value);  // OK, I CAN SEE THIS DISPLAYED FOR EACH TYPE

   // QUERY OTHER STUFF BASED ON THE VALUE OF "type"
   var query = client.query(...);

   // MAIN STUFF
   (function(t, v) {
     query.on("row", function(row) {
       console.log('TEST:' + t + ',' + v); // KO, I CAN ONLY SEE THIS DISPLAYED FOR ONE TYPE
   }); })(type, value);

   // FINALIZE
   query.on('end', function(){
      ...
   }      
}
  • 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-05-23T05:08:38+00:00Added an answer on May 23, 2026 at 5:08 am
    with ({ t: type, v: value }) {  // I HAD TO DO THAT SO THAT ALL THE TYPES ARE TAKEN INTO ACCOUNT
          query.on('end', function() {
            my_function(t, v);
          });
        }
    

    Is broken. What you want is this

    query.on("end", my_function.bind(null, type, value));
    

    Function.prototype.bind allows you to bind parameters to a function.

    Never use with. An alternative that also works would be :

    (function(t, v) {
      query.on("end", function() { my_function(t, v); });
    })(type, value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class CustomCollection : IList which maintains a list of CustomObject Types.
I have IQueryable list of objects of type T which I want to transform
I have an object of type list from which I wish to use to
I have ControlA which accepts an IInterfaceB which has a property of type List<unknownType>
I have the following LINQ query: List<string> Types = (List<string>)Directory.GetFiles(@C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727) .Where(x => System.IO.Path.GetFileNameWithoutExtension(x).Contains(Microsoft)) .ToList<string>();
I have a List(Of String) which corresponds to types on our database table. We
I have an ul list with a query and a while loop displaying the
I have a php for each loop which outputs a form for every product
Possible Duplicate: Java - Regex problem I have list of URLs of types: http://www.example.com/pk/etc
I have a situation in C# where I have a list of simple types.

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.