Sunday, August 3, 2014

Web Workers in practice - Integration (HTML5)

Intro

Couple of years ago, web workers (along with other HTML5 stuff) suddenly became popular. On the  spike of their popularity, many tutorials were written. However, the moment of popularity was very brief, mainly because, well, you don't need this in your regular JS application. The common use case - blocked UI because of long-running script - is rather rare if you use modern browser with fast JS engine.
Have you really seen something like that recently?
In lots of tutorials all the workers did was passing messages to main script, where it was printed to console or put in some DOM element, which doesn't give you any feeling of concurrency at all.
More advanced ones included prime number sequence generation, which was more like it, as this is a really long operation, especially when you generate a long sequence :)
In this tutorial I'll try to show another example how web workers could be useful in practice - in other math problem.