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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:56:54+00:00 2026-06-17T09:56:54+00:00

I have the following pattern which strings together function1, 2 and 3 through their

  • 0

I have the following pattern which strings together function1, 2 and 3 through their callbacks.

Assume that function1, 2 and 3 can take up to 1 second to complete. I would like to know other “better” ways of doing the same so that it doesn’t turn into a monster when more callback functions are nested.

function1(function(cbData1){
  if(cbData1){
    function2(cbData1, function(cbData2){
      if(cbData2){
        function3(cbData2, function(cbData3){
          // success
        }
      } else {
        // failed for reason#2
      }
    });
  } else {
    //failed for reason#1
  }
});


//example function
function function2(data, callback) {
  // do dirty things
  callback(newData);
}
  • 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-17T09:56:56+00:00Added an answer on June 17, 2026 at 9:56 am

    The last time I played with really nasty callbacks, I ended up doing something like this:

    // Typed on the fly, be kind
    var callbackList = [];  // A list of functions to call in order.
    
    function doNextCallback() {
      if (callbackList.length) {
        var f = callbackList.shift(); // Get the next callback function
        window.setTimeout(f);         // Give breathing space.
      }
    }
    
    // Set up our callbacks
    callbackList.push(f1);
    callbackList.push(f2);
    callbackList.push(f3);
    
    // Start it happening.
    doNextCallback();          
    
    
    function f1() {
      console.log("Busy busy");
      doNextCallback();
    }
    
    function f2() {
      console.log("Busy busy");
      doNextCallback();
    }
    function f3() {
      console.log("Busy busy");
      doNextCallback();
    }
    

    I had it all wrapped up in a nice object, but you get the idea.

    This also made it very easy to re-arrange callbacks or to call just two of them in a big loop for testing purposes.

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

Sidebar

Related Questions

Say I have the following pattern: INDICATOR\s+([a-z0-9]+) which would match for example: INDICATOR AA
I have a script that utilizes a hash, which contains four strings as keys
Looking for regex solution for following scenaio: I have strings, which i have to
I have a fairly long string that contains sub strings with the following format:
I have several strings that look like the following: +H124005992014011/1527399999999I05Z +H7039700000001/$99999999I051 +K122005962050171/120911234C117 I need
I have some strings that I would like to pattern match and then extract
I have a C# collection of strings. Each string is a sentence that can
I have the following patterns and grouping application which I am refactoring in one.
I have the following pattern matching case in a scala function: def someFunction(sequences: Iterable[Seq[Int]]):Seq[Int]
I have the following pattern: template <int a, int b> class MyClass { public:

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.