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

  • Home
  • SEARCH
  • 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 8924363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:23:27+00:00 2026-06-15T07:23:27+00:00

I have a async function that breaks it’s callbacks into an object success and

  • 0

I have a async function that breaks it’s callbacks into an object success and error, this function takes one param (besides the callback) "pink".

async("pink",{
    success:function(){

    },
    error:function(){

    }
});

I want to make plural version of this function that takes in an array and returns the true or false value for the async action.

asyncs(["blue","red","green"],function(values){
    console.log(values); // [true,true,true];
});

The trick is that each acync action needs to be within the next, the value of the function (true or false) needs to be pushed() into a “global” (higher in scope) variable values and the returned in a master callback(values) at the end (when the count reaches the array length)

This is a very rudimentary way of nesting each async() function and returning the values, it is limited because it manually trails only 3 array values.

var asyncs = function(params,mstrCB){
    var length = params.length;
    var values = [];
    async(param[0],{
        success:function(){
            values.push(true);
            async(param[1],{
                success:function(){
                    values.push(true);
                    async(param[2],{
                        success:function(){
                            values.push(true);
                            mstrCB(values);
                        },
                        error:function(){
                            values.push(false);
                            mstrCB(values);
                        }
                    });
                },
                error:function(){
                    values.push(false);
                     mstrCB(values);
                }
            });
        },
        error:function(){
            values.push(false);
            mstrCB(values);
        }
    });
};  
  • 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-15T07:23:28+00:00Added an answer on June 15, 2026 at 7:23 am

    Use a counter instead of manually nesting. Put the request in its own function, and up on each success, increment the counter and if it’s less than length, make a new request.

    When i === length, call the mstrCB().

    var asyncs = function(params,mstrCB){
        var length = params.length;
        var values = [];
        var i = 0;
    
        if (length)
            makeRequest();
    
        function makeRequest() {
            async(params[i], {
                success:function(){
                    values.push(true);
    
                     // Increment the counter
                    i++;
    
                    if (i === length)  // we're at the end
                        mstrCB(values);
                    else
                        makeRequest(); // there's still more, so make another request
                },
                error:function(){
                    values.push(false);
                    mstrCB(values);
                }
            });
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so I have a function that exports some data async via asp.net and displays
I have a recursive function that spawns several async tasks. Each task updates a
I have a function that calls an async function. My examples use ajax, but
lets say i have this async functuin: function fooAsync(){ callSomeApi(some_args, callbackFunction(results){ return results; //i
I have a downloader function that downloads multiple files parallely. I use multiprocessing.Pool.map_async in
I have async methods that returns an objects public static IEnumerable<Users.User> GetUsers(IEnumerable<string> uids, Field
I have this sample code for async operations (copied from the interwebs) public class
I have some functionality that needs to be async in my C# app. It's
Scenario 1 (That Works) This is a POC i created. I have a script
I call a function that stacks two async calls and calls a callback when

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.