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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:14:49+00:00 2026-06-12T09:14:49+00:00

This is more than a question, it is a request to ensure the Quality

  • 0

This is more than a question, it is a request to ensure the Quality of Service (QoS) of Javascript’s timeout function.

Looking at the following pseudo-code:

  .. start something in JS after a user action
  .. some js code
  setTimeout( function() { doSomething }, 1 );
  .. continue for longer than 1ms doing something
  .. end code for user action

  .. after 

  .. execute doSomething

Can we be sure that on all major browsers, the code of the timeout is done after the code has handled the first user action? This is independent of the delay time.

The delay time is not important, rather the fact ‘doSomething’ code is executed after.

What happens with 0 delay?

Thanks in advance for your experience on different browsers.

  • 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-12T09:14:50+00:00Added an answer on June 12, 2026 at 9:14 am

    When an asynchronous event “fires” is different from when it actually executes, due to Javascript’s single-threaded nature.

    Each block of code being evaluated is represented internally as a task in a task queue. So let’s say that in the middle of a given block of code, an asynchronous event is prepped for execution via setTimeout(). If the delay is short enough, in practice nothing’s stopping it from “firing” before the rest of that same block of code is finished executing. However “firing” doesn’t mean that the setTimeout handler actually interrupts and executes. It just means that it’s turned into a task on a task queue. Actual execution still has to wait until it is popped off of the task queue, and that can’t happen until the original block of code is finished.

    Here’s an HTML5 spec snippet that, while not authoritative for all browsers of course, being HTML5, is illustrative:

    http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#processing-model-3

    The first of 7 steps defined there for the main event loop is:

    1. Run the oldest task on one of the event loop’s task queues, ignoring tasks whose associated Documents are not fully active […]

    Note that this first step is atomic. The task must run to completion before the environment is reset and the next task is picked up.

    Also have a look at John Resig’s post on this:
    http://ejohn.org/blog/how-javascript-timers-work/

    So, wrt your question:

    Can we be sure that on all major browsers the code of the timeout is done after the code handling the first user action. This independently of the delay time.

    … the answer is yes, we can be sure. (In the vanilla case… I assume we’re only talking about the traditional single/UI thread, and not talking about processing by Web Workers).

    Also, although you did mention that you don’t care as much about the delay time per se, still you may be interested to note the “clamp time” (enforced minimum delay) as well, which appears to be de facto standardized at around 4ms.

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

Sidebar

Related Questions

Good day, This is more web service design than programming question I think. I'll
this is more than a question, a request for advice. How resource expensive would
Alright I know this is more than likely a amateur question but I have
This is more of a philosophical question than anything, so give me your thoughts.
(This is more of a curiousity question than any pending disaster :D ) So
This is more of a maths question than programming but I figure a lot
This is more of a theoretical question than an actual problem I have. If
This is related to my previous question More than 1 Left joins in MSAccess
Of Note : This is more of a curiosity question than anything else. Given
This question is more philosophical than technical. I've trained myself as a web developer

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.