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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:41:08+00:00 2026-06-02T17:41:08+00:00

Normally an asynchronous function, let’s say async(arg, cb) , provides a callback function placeholder

  • 0

Normally an asynchronous function, let’s say async(arg, cb), provides a callback function placeholder (cb) at the end so you can run your own code when the asynchronous routine ends. What if the asynchronous function has no callback argument? Clearly with cb missing in:

async(args);
myFunction();

myFunction() will run first. How can I make myFunction() run only after async ends? I tried writing my own callback wrappers without success; they were merely redirecting the function calls.

EDIT I’m interested in an answer to the above but I will give an example of how I ran into this situation.

My example is in the Google Maps Directions service. The asynchronous function is a drawing routine called directionsDisplay.setDirections(result);, and I want to recenter and zoom in after the drawing completes. I put together a setTimeout of 3 seconds so that what I want happens, but it’s a clumsy solution. Altering the Google Maps API seems out of the question. What could be better?

The directions service is here.

http://jsfiddle.net/ryxtj/1/

Simply choose a city in either dropdown. After 3 seconds the map should move.

  • 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-02T17:41:12+00:00Added an answer on June 2, 2026 at 5:41 pm

    A simple Google search found me this related post: Google Maps V3 setDirections() callback

    Which shows adding an event listener for when the directions change.

    Javascript is single threaded and does NOT have synchronization capabilities like semaphores or mutexes. Thus, there is no ability to make your code “wait” until an async function completes or turn an async function into a synchronous one.

    The only way to solve this is with event handlers and/or callback functions. No self respecting provider of APIs will give you an API to an asynchronous function without some ability to know when it completes. If they do, it’s a really crummy API and you’d have to go into the source implementation for that API, find where the completion of the event is handled and install a callback (by modifying the original source). Unless they’ve already provided for completion events or completion callbacks in the design, there’s nothing else you can do from “outside” the code.

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

Sidebar

Related Questions

Normally, I would use a callback function passed to the 'jQuery.getJSON' function to do
Normally with Java Swing you can set the background color of a button with:
Normally if I run the following the following command in the rhino shell, mbp001:rhino1_7R2
The concept of message is normally associated with asynchronous call. Is it the case
Normally, we can do loops for both arrays and objects to iterate over the
Normally, we can create properties like this, dynamic expando = new ExpandoObject(); expando.Price =
Normally I can do something like this to fill up the byte array with
Normally the easiest way to debug is using printf . What can I do
Normally whenever a CAPTCHA might be needed I always present it to the user
Normally, when I want to allow a user to download a file without revealing

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.