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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:03:38+00:00 2026-05-27T07:03:38+00:00

This is an odd problem. I have a client object that I am building

  • 0

This is an odd problem. I have a client object that I am building up using Crockford-esque public/private members:

var client = function() {
  var that, remote_data, other_data; 

  // add public interface
  that.doStuff = function(){...}

  // wait for remote resources to load
  remote_data = jsonRequest1();
  other_data  = jsonRequest2();

  return that;
};

The problem I’m having is that I need to load some remote JSON resources prior to returning the new ‘that’ object (which signals a ready client). Data is returned asynchronously (obviously), and I am setting boolean variables to indicate when each remote resource has returned.

I’ve thought about doing something like the following:

return whenInitialized(function() { return that; });

The whenInitialized function returns whether or not both of the boolean flags are true. I’d use this with a combination of setInterval, but I am sure this won’t work.

Would appreciate your suggestions.

  • 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-27T07:03:38+00:00Added an answer on May 27, 2026 at 7:03 am

    In order to run code after an asynchronous operation has succeeded, you need a continuation. It can be just a callback that your code calls when the operations are complete.

    Something like this:

    var client = function(done) { // done is the callback
      var that, remote_data, other_data; 
    
      // add public interface
      that.doStuff = function(){...}
    
      // wait for remote resources to load
      var done1 = false, done2 = false;
      var complete1 = function() { done1 = true; if (done2) done(); };
      var complete2 = function() { done2 = true; if (done1) done(); };
      remote_data = jsonRequest1(complete1);
      other_data  = jsonRequest2(complete2);
    
      return that;
    };
    

    But these controlling flags are really annoying and don’t really scale. A better, declarative way of doing this is using something like jQuery deferreds:

    $.when(jsonRequest1(), jsonRequest2()).then(done);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PuTTY to log into a Debian server. I have this odd problem
This is an odd problem, so I have to provide a bit of background.
I have this odd problem with a third party script. On our site a
I am seeing this somehow odd problem (even though I have the feeling I
This is my first question on S.O. I have a very odd problem. Below
I have this odd problem with Spring AOP and I am hoping someone can
I have an odd problem with captureStillImageAsynchronouslyFromConnection. If I save the image using jpegStillImageNSDataRepresentation
I have an odd problem...I'm using a documentation generator which generates a lot of
I have the odd problem that I am not able to open the properties
I have an odd problem that I've been beating my head into a wall

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.