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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:04:17+00:00 2026-05-28T18:04:17+00:00

I am having a synchronization issue with third party API. My for loop seem

  • 0

I am having a synchronization issue with third party API.

My “for loop” seem to be running quickly, throwing off API requests
which may return data in any order.

How can I restructure this to endure that DoSomething is run synchronously?

function startgeocoding() {
    for(var x = 0; x < address2.length; x++ ) {
        geocode(address);
    }
}

function geocode(address) {
    if (geocoder) {                 
        geocoder.geocode({ 'address': address  }, function (results, status) {          
        if (status == google.maps.GeocoderStatus.OK) {
            DoSomething();
        }
    }
}
  • 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-28T18:04:18+00:00Added an answer on May 28, 2026 at 6:04 pm

    You could call geocode() on the next element in the success callback to create a chain of calls. The calls would still be asynchronous but you aren’t geocoding the next one until the first one finishes. Something like:

    var addresses = [];
    
    // this function really is optional, it's just copying an array
    function startGeocoding() {
        for (var x = 0; x < addresses2.length; x++) {
            addresses.push(addresses2[x]);
        }
        geocode(addresses.shift());
    }
    
    function geocode(address) {
        if (geocoder){                   
            geocoder.geocode({ 'address': address  }, function (results, status) {          
                if (status == google.maps.GeocoderStatus.OK) {
                    DoSomething();
                    if (addresses.length > 0) {
                        // take first value
                        geocode(addresses.shift());
                    }
                } 
            });
        }
    }
    

    Another option might be to leave it the way you have it, but queue up the results, sort them somehow, and then do work on them once all of the synchronous calls have completed in the order you wish.

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

Sidebar

Related Questions

I am relatively new to objective-c, and having an issue of thread synchronization. I
I am having an application which has a UI module and other supporting services.
HI all, I am having a thread Checker (extends thread class) which keeps on
I am having some difficulty understanding callbacks and program flow, synchronization issues. Lets say
I've written a simple FTP based file synchronization program. The settings of which can
I having some synchronization issues using the OpenMPI implementation of MPI_Barrier: int rank; int
I'm having a strange issue. In a class I have: private final ScheduledExecutorService executor
Having a issue where all mobile devices is zoomed 50% in at start. That
We're having a compatibility problem between Mercurial and another synchronization product (MS Office Groove,
Having been a PHP developer on LAMP servers for quite a while, is there

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.