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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:07:10+00:00 2026-06-09T15:07:10+00:00

I made a goog.Timer object ( http://closure-library.googlecode.com/svn/docs/class_goog_Timer.html ) with new goog.Timer(1) to run a

  • 0

I made a goog.Timer object (http://closure-library.googlecode.com/svn/docs/class_goog_Timer.html) with new goog.Timer(1) to run a function every millisecond via listening to the tick event. However, the function seemed to be running every 100 milliseconds instead.

I hypothesized that my function was taking a while to run (and javascript is single-threaded of course), so it took a while to get to the next round. Hence, I set the interval for the timer to 100, and it reliably ran every 1/10 of a second.

Does The Google Closure library have a more reliable timer that only runs a function precisely at the interval? If there is not enough time to run a function in one cycle, I am fine with canceling the previous call and running it the next time a tick is dispatched.

  • 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-09T15:07:11+00:00Added an answer on June 9, 2026 at 3:07 pm

    Nicholas Zakas wrote up a nice summary of Timer resolution in browsers on his blog. As Nicholas pointed out, the HTML5 timers specification (as of August 2, 2012) dictates that the minimum interval for setTimeout() and setInterval() is 4 milliseconds.

    I wrote the following demo application to test the minimum interval delay for goog.Timer.

    <!doctype html>
    <html>
    <head>
      <title>goog.Timer Test</title>
      <script src="../closure-library/closure/goog/base.js"></script>
    </head>
    <body>
    
    <h1>goog.Timer Test</h1>
    
    <div id="mainContent"></div>
    
    <script>
      goog.require('goog.Timer');
    </script>
    <script>
      var tickCount = 0;
      var timer = new goog.Timer(1);
      var mainDiv = document.querySelector('#mainContent');
    
      /**
       * Tick callback.
       */
      var tickCounter = function() {
        tickCount++;
        if (tickCount % 1000 === 0) {
          var timeElapsed = goog.now() - startTime;
          mainDiv.innerHTML = 'goog.Timer tick events: ' + tickCount +
              '<br>actual elapsed milliseconds: ' + timeElapsed +
              '<br>milliseconds per goog.Timer tick: ' + timeElapsed/tickCount;
        }
      };
    
      startTime = goog.now();
      timer.start();
      goog.events.listen(timer, goog.Timer.TICK, tickCounter);
    </script>
    </body>
    </html>
    

    Running this program in Chrome version 21 consistently shows approximately 4.2 milliseconds per goog.Timer tick event, which is very close to the minimum allowable browser timer resolution of 4 milliseconds.

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

Sidebar

Related Questions

I made a subclass of goog.ui.Button in my Google Closure javascript. /** * @fileoverview
Made a fiddle for this: http://jsfiddle.net/terjeto/MN4FJ/ My problem is that dragleave fires when you
Made a new window application. Right-clicked Frameworks > Add Existing Frameworks. Selected Frameworks folder,
I made this server class that starts a thread when new connection comes in.
I made a page using HTML which have some .jpg files and some .swf
Edit: Made an official bug report at developers.Facebook.com GETing either of the following: graph.facebook.com/me/photos
Made solution change: I am trying to display a html table of data.. In
made an object, MyTextBoxCreator. i need to make lots of text boxes dynamically. i
I made a subclass of goog.ui.Component: /** * Renders the bottom pane. * @param
In my Google Closure code, I made an enum denoting names of CSS classes

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.