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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:37:59+00:00 2026-05-15T06:37:59+00:00

Hey guys, im not well versed in dealing with asynchronous design patterns, and im

  • 0

Hey guys, im not well versed in dealing with asynchronous design patterns, and im having a problem writing a script that does two async data fetches.

Im using Dojo.data.api.Read.Fetch() to make two fetch() calls from seperate databases. The reulsts come back asynchronously. However, I have to cross reference the results, so i want my script to continue once BOTH async fetches are complete. I dont know how to do this, and therein lies the problem.

I am aware of the fetch’s onComplete field and how to use it, BUT the best case solution i see there is to call the second fetch in the onComplete of the first fetch. I would like to do these fetches at the same time. Is there a way to do this?

Here’s the current structure of my program for illustration purposes:


this.dict1.fetch({query:"blahblahblah", onComplete: function(items) { something here? }});
this.dict2.fetch({query:"blahblahbleh", onComplete: function(items) { or maybe something here? }});
this.orMaybeDoSomethingAfterBothFetches()

Any help would be greatly appreciated!

  • 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-15T06:38:00+00:00Added an answer on May 15, 2026 at 6:38 am
    // this is a variation of a function I have answered quite a few similar questions on SO with
    function collected(count, fn){
        var loaded = 0;
        var collectedItems = [];
        return function(items){
            collectedItems = collectedItems.concat(items);
            if (++loaded === count){
                 fn(collectedItems);
            } 
        }
    }
    
    var collectedFn = collected(2, function(items){
        //do stuff
    });
    
    
    this.dict1.fetch({query:"blahblahblah", onComplete: collectedFn);
    this.dict2.fetch({query:"blahblahbleh", onComplete: collectedFn);
    

    An alternative solution is

    var store = {
        exec: function(){
            if (this.items1 && this.items2) {
                // do stuff with this.items1 and this.items2
            }
        }
    };
    
    this.dict1.fetch({query:"blahblahblah", onComplete: function(items) {
        store.items1 = items;
        store.exec();
    });
    this.dict2.fetch({query:"blahblahbleh", onComplete: function(items) {
        store.items2 = items;
        store.exec();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I have a weird problem. I have an update system that refreshes
Hey guys, I have a little button functionality that is not erring, but also
Hey guys, I'm using Twitter's PHP API, called twitterlibphp , and it works well,
Hey guys. I'm not much of a programmer, but still need to do some
hey guys, m building a web-page in that theres a tag which holds some
hey guys,i'm new to mysql.here i wrote a procedure that error occured: DELIMITER $$
Hey guys. I'm having this silly issue with inserting text with forwardslash into cart
Hey guys, I'm using GWT for a data-driven web application, and I'm having issues
Hey guys, I'm new to Java (well, 3/4 of a year spent on it).
Hey guys and girls. I have a method that creates rain particles, tiny images,

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.