Multi-Threading JavaScript

I promise, I’ll keep this one quite short, I’d just like to take a moment to talk about how easy it is to achieve multi threading in JavaScript, without the need for an array of files, which is what I’d imagine a lot of people do or have done in the past. I’ve implemented a way in which it’s possible to implement web workers running from the same JS file, kinda.

Without any delay, here’s an example of what the code may look like:

This example is incredibly simple, yet effective, the code that allows you to achieve this can be found here. I wrote this code quite some time ago, if anything to be perfectly honest, it was so long ago for me now, looking back at it, I’m a bit embarrassed 😶. However, regardless of its current state, it’s simple, yet effective, I mean if I were to write it today, I’d probably have some management class around this, maybe utilise an observable pattern so that when the thread finishes, you can subscribe to it rather than using a callback function, etc.

If you’re unsure of how the underlying code that I’ve written works, I’d strongly suggest that you look more into web workers to start with, maybe look more into how the event loop works also. Afterall, the more you know, the better! 🙂 But apart from those two suggestions, there’s not much more to add than that, the rest is pretty straightforward & simple.

Similar Posts

  • Ambitions: 2020

    First of all… Happy new year! 🥳 All round 2019 wasn’t too bad, career wise I was able to achieve working for an enterprise company, rather than a start up, which of course opened my eyes to new technologies & processes. For the following years I have a lot of ambitions, one being progressing to…

  • Organic vs Artificial

    Introduction Don’t worry, I won’t bore you by talking about the likes of food & how things are grown, processed, etc. Rather, I’d like to revisit the topic of artificial intelligence, and review its weak points at this moment in time. If you’ve read my previous articles, you’ll know that I’m not one of those…

  • |

    Empowering The Backend

    Introduction I’ve been involved in all kinds of web-based projects throughout my career so far. I hope that pattern continues & I even hope that someday, I can even go out of my comfort zone & deal with technologies beyond the web. Be that embedded systems programming for IoT devices or just building some silly…

Leave a Reply

Your email address will not be published. Required fields are marked *