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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:14:38+00:00 2026-06-05T22:14:38+00:00

I am currently experimenting with asynchronous function-calls in jQuery and am stuck. Consider the

  • 0

I am currently experimenting with asynchronous function-calls in jQuery and am stuck. Consider the following example:

<html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            f = function() {
                alert("f1");
                var x = 0;
                for (var i = 0; i < 2500000000; i++) {
                    x++;
                }
                alert("f2");
            }

            $.when( f() ).done(alert("done"));
            alert("moving on...");
        </script>
    </body>
</html>

I would expect the alert-messages in the following order: “f1”, “moving on…”, “f2”, “done”
But when I run the code in Chrome, what I get is this: “f1”, nothing happens for 10s, “f2”, “done”, “moving on…”. This doesn’t look asynchronous to me. Am I doing something wrong or is this the intended behavior? If so, what is the whole point of using the when-function and the callback? Couldn’t I just call the function f synchronously?

  • 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-05T22:14:40+00:00Added an answer on June 5, 2026 at 10:14 pm
     $.when(f())
    

    This calls f() immediately (like any other function call), then passes the result to $.when.

    $.when() does not magically make a function asynchronous; it can only work with existing asynchronous operations (eg, AJAX).

    The only way to do actual multi-threading in Javascript is to use Web Workers.

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

Sidebar

Related Questions

I currently experimenting with different lightweight text editors for Scala development. jEdit seems to
I'm currently experimenting with build script, and since I have an ASP.net Web Part
I'm currently experimenting with generics in C#, and came up with the following challenge
I'm currently experimenting with EJB3 as a prestudy for a major project at work.
I'm currently experimenting with the sample SoftKeyboard on my tablet (Android 3.2). When I
Currently, i'm experimenting with a very simple GUI drawing ... engine (i guess you
I am experimenting with filter_input and filter_var and I am currently trying to sanitize
I am experimenting with writing a toy compiler in ocaml. Currently, I am trying
I'm experimenting with Protocol Buffers in an existing, fairly vanilla Maven 2 project. Currently,
I'm currently working with jQuery 1.4.2 and jQuery UI 1.8.2. I'm experiencing some weird

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.