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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:20:55+00:00 2026-06-01T02:20:55+00:00

Edit: We can close. Isn't truly asynchronous, non-blocking javascript impossible? var PATH = require

  • 0

Edit: We can close. Isn't truly asynchronous, non-blocking javascript impossible?


var PATH = require ("path");
var URL = require ("url");

var sleep = function (ms){
    var start = new Date ().getTime ();
    while ((new Date ().getTime () - start) < ms);
}

require ("http").createServer (function (req, res){
    if (URL.parse (req.url).pathname === "/1"){
        console.log ("tab 1: I'm in");
        PATH.exists ("test", function (exists){

            sleep (5000);

            res.writeHead (200, {"Content-Type": "text/plain"});
            res.end ("1");
            console.log ("tab 1: I'm done");
        });
    }else{
        console.log ("tab 2: I'm in");
        res.writeHead (200, {"Content-Type": "text/plain"});
        res.end ("2");
        console.log ("tab 2: I'm done");
    }
}).listen (80);
  1. Copy the content into a file.
  2. Execute the file.
  3. Open a new tab in browser. Set the url to localhost/1. Don’t go yet.
  4. Open a new tab in browser. Set the url to localhost/2. Don’t go yet.
  5. Go back to the first tab. Press enter and immediately after change to the second tab and press enter.

Result:

  • console log:

    tab 1: I’m in
    tab 1: I’m done
    tab 2: I’m in
    tab 2: I’m done

  • Tab 1 waits 5 seconds to receive the result “1”.

  • Tab 2 also has to wait 5 seconds because tab 1 is sleeping for 5 seconds.

The docs says that all is asynchronous except the code. Only one thread. Only one request at a time. Requests are enqueued.

I/O calls are supposed to be asynchronous, right? Then why tab 2 has to wait to tab 1 if the callback comes from an asynchronous I/O process?

Thanks.

  • 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-01T02:20:57+00:00Added an answer on June 1, 2026 at 2:20 am

    Because your sleep is blocking the event loop.

    Replace it with setTimemout(function() { /* Code to run */ }, 5000); and watch /2 respond immediately.

    The actual I/O is asynchronous, but all actions you’re performing on the I/O happen in the event loop. If something is blocking the event loop, everything else has to wait, just like you said.

    EDIT. For more clarity, look at the following ASCII graphic:

    Event Loop Thread: ------+req1HandlerExistsCall+-------+req1Wait5Sec++++++++++++++++++++++++++req2ExistsCall+-------+req2Immediate+-------------
             HTTP I/O: -+req1+--------------------------------------+req2+--------------------------------------+req1Response+--------+req2Response+
             File I/O: ----------------------------+exists1+----------------------------------------------------+exists2+---------------------------
    

    Basically, only one at a time for each thread. Because the first request handler blocks for 5 seconds (and it’s essentially impossible to beat your filesystem with your fingers in a speed test), the second response doesn’t even start to be handled until the first request is almost done.

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

Sidebar

Related Questions

Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
EDIT: You can see the search box live here . Before I explain, let
Edit: I can use Actionscript 3.0 and/or Java I have a bit of a
Are there any editors that can edit multi-gigabyte text files, perhaps by only loading
Is there a tool where you can edit a .NET dll directly? .net reflector
In the below code onclick edit how can the value of tag test be
Is there any external library using which one can edit and save XML files
I have a page where the user can edit various content using buttons and
I've got a form where users can edit members of a group. So they
---- PLEASE CLOSE ---- ------ Edit --------- I found where the problem is. I'm

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.