Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

8. WebWorker API > Hack 66. Use a Timer to Send Application State to Workers

Hack 66. Use a Timer to Send Application State to Workers

The combination of timers and web workers opens new opportunities in the development of client-centric HTML5 applications. It is possible to make your application artificially intelligent (in a very basic way) by giving it a set of functions called at a regular interval. Although these operations can be performed in the main thread, it is often optimal to perform them in a separate worker thread process.

In this hack we will gain inspiration from Angus Croll’s post, “web workers vs. the crazy flies”.

For the most part, we will use most of Angus’s design, where he animates flies that are eliminated over time based on array manipulations being performed within web workers (see Figure 8-9). We will do much the same thing, but add our own flavor to the hack.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint