Workers - Learning about Dedicated and Shared Workers

In the past few chapters, we have focused on Node.js and how we can write backend applications utilizing the same language as the frontend. We have seen various ways of creating servers, offloading tasks, and streaming. In this part, we will focus on the offloading tasks aspect of the browser.

Eventually, as we have seen in Node.js, we need to offload some computationally intensive tasks from the main thread to a separate thread, or process, to make sure that our application stays responsive. While the effects of having a server not respond can be quite jarring, the effects of our user interface not working are downright off-putting to most users. Therefore, we have the Worker API.

In this chapter, we will specifically look at two kinds of workers, dedicated and shared. Overall, we will do the following:

  • Learn to offload heavy processing to a worker thread via the Worker API.
  • Learn how to talk with workers via the postMessage and BroadcastChannel APIs.
  • Talk about ArrayBuffer and the Transferrable property so we can quickly move data between workers and the main thread.
  • Look at SharedWorker and the Atomics API to see how we can share data between multiple tabs of our application.
  • Take a look at a partial implementation of a shared cache utilizing the knowledge from the previous sections.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.190.232