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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:32:50+00:00 2026-06-11T02:32:50+00:00

I am working on an HTML5 mobile web app built on top of SalesForce.

  • 0

I am working on an HTML5 mobile web app built on top of SalesForce. We make heavy use of JavaScript Remoting functions and I would like to know a way to wait for N (multiple) of these remote function calls to complete and then fire another event or function call. The use case we are trying to accomplish is as follows:

  1. Show jQuery Spinner/Loader with $.mobile.showPageLoadingMsg();
  2. Call Remote function 1, 2, 3, …, N.
  3. Wait for Remote functions 1, 2, 3, …, N to return but do NOT freeze the browser.
  4. Hide the jQuery Spinner/Loader with $.mobile.hidePageLoadingMsg();

    // Show a Loading Spinner while we wait for our remote requests to complete.
    $.mobile.showPageLoadingMsg();
    
    // Remote Request 1
    MyController.f1(
        function(result, event){
            if(event.type == 'exception') {
                alert('Error: ' + event.message);                     
            } else {
                // Do stuff here such as fill in a form with the results from f1
            }
        },
        {escape:true});
    
    // Remote Request 2
    MyController.f2(
        function(result, event){
            if(event.type == 'exception') {
                alert('Error: ' + event.message);                     
            } else {
                // Do stuff here such as fill in a form with the results from f2
            }
        },
        {escape:true});
    
    // ...
    
    // Remote Request N
    MyController.fN(
        function(result, event){
            if(event.type == 'exception') {
                alert('Error: ' + event.message);                     
            } else {
                // Do stuff here such as fill in a form with the results from fN
            }
        },
        {escape:true});
    
    // I want to wait until all of my requests to finish before I hide the loading spinner.
    wait_for_all(); 
    $.mobile.hidePageLoadingMsg();  
    
  • 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-11T02:32:52+00:00Added an answer on June 11, 2026 at 2:32 am

    here is how I generally handle this case:

        function doManyAsync(doneCallback) {
            // Async worker counters
            var workers = 0;
    
            function tickWorkers() {
                workers--;
                if ( workers === 0 ) {
                    if ( doneCallback )
                        doneCallback();
                }
    
            }
    
            // Queue off first one
            doAsyncFunc1(1,2,3, tickWorkers);
            workers++;
    
            // Queue off second
            doAsyncFunc2(function() {
                tickWorkers();
            });
            workers++;
            
        }
    

    An async worker counter is used outside of the async function’s scope to keep track of them. For each async function started, increment the counter. When they finish, the callback will decrement until they are all done and call the finished callback. This relies on the incrementing for every function. If there is a risk of the async functions failing then you can set a timeout to check every now and then for the worker count, and if it hits past a threshold and its not 0 then to fail or generate an error, as desired.

    Here is how it might look with your code:

        function doManyAsync(doneCallback) {
    
            // Async worker counters
            var workers = 0;
    
            function tickWorkers() {
                workers--;
                if ( workers === 0 ) {
                    if ( doneCallback )
                        doneCallback();
                }
    
            }
    
            // Remote Request 1
            MyController.f1(
                function(result, event){
                    tickWorkers();
                    if(event.type == 'exception') {
                        alert('Error: ' + event.message);                     
                    } else {
                        // Do stuff here such as fill in a form with the results from f1
                    }
                },
                {escape:true});
            workers++;
    
            // Remote Request 2
            MyController.f2(
                function(result, event){
                    tickWorkers();
                    if(event.type == 'exception') {
                        alert('Error: ' + event.message);                     
                    } else {
                        // Do stuff here such as fill in a form with the results from f2
                    }
                },
                {escape:true});
            workers++;
    
            // ...
    
            // Remote Request N
            MyController.fN(
                function(result, event){
                    tickWorkers();
                    if(event.type == 'exception') {
                        alert('Error: ' + event.message);                     
                    } else {
                        // Do stuff here such as fill in a form with the results from fN
                    }
                },
                {escape:true});
            workers++;
    
        }
    
        // You would then
        $.mobile.showPageLoadingMsg();
        doManyAsync(function() {
            $.mobile.hidePageLoadingMsg();
        })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a mobile web-app using sencha touch, HTML5 and phonegap as a
I'm working on an html5 application built on CouchDB. I want to make sure
I am working on a mobile web app that outputs a number of CSS,HTML
I am making mobile web app in Html, css, javascript, jquery . I am
I am working on a EDIT: mobile web app which displays some sensitive information
I'm working on a mobile web app and I've noticed on both my test
I am working on a rails web app, currently focusing on the mobile design
I'm working on an online multiplayer mobile web app that runs 100% in the
I had a great working PhoneGap mobile web-app project, then my laptop died. I
I'm working on a mobile web app using Rails and jQuery Mobile. I've got

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.