Working with parallel functions
JavaScript provides concurrency through async
functions, meaning that several tasks can go on at the same time, even if a single CPU is doing all the jobs. Web workers (for the frontend) and worker threads (for the backend) allow processing in parallel in a different core, for better performance. This can offload work from the main thread and solve potential problems, in line with our FP approach.
In this section, we’ll see how to avoid bottlenecks in frontend and backend programming by using workers in functional ways, along the lines of the previous sections in this chapter.
Unresponsive pages
Let’s return to our Fibonacci slow-performing code from the Memoization section in the previous chapter. Suppose we want to create a web page that will allow users to enter a number and calculate the corresponding Fibonacci number, as in Figure 5.6.
Figure 5.6 – A Fibonacci calculator
The code for this...