• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Secrets of the JavaScript Ninja: What are Taming timers?

 
Ranch Hand
Posts: 100
2
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brief about what exactly is Taming timers and why are they used in JavaScript?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Timers are used for many things in JavaScript. From simple "make something happened in 2 minutes" to breaking up computationally intensive operations.

JavaScript is single-threaded. So when some computationally intensive operation is underway, it "hogs" the execution queue. Timers can be used to execute the operation in chunks to let other operations get into the execution queue,

Interval timers can be used to schedule operations to occur at set intervals of time. For example, refreshing the data on the page using Ajax once every minute.

Because JavaScript is single threaded, knowing exactly how timers and intervals act can get complex if things get busy. For example, what happens if a timer goes off while another is processing its callback? What happens to intervals if the execution queue is busy while a timer or another interval fires? What happens if multiple timers or intervals all go off at the same time?

The Taming Timers chapter of Secrets of the JavaScript Ninja explains exactly how timers and intervals work, and how they react in the single -threaded environment of JavaScript when there is contention for the execution queue.
 
M Khalid
Ranch Hand
Posts: 100
2
Python Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Bear Bibeault
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic