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

  • | | |

    QOS Status Report

    I’ll keep this one relatively short. I just thought that I’d share what I’ve been up to lately, I’m currently a very, very busy bee! 🐝 One thing that I’ve recently worked on at QuoteOnSite is what we’re calling the content library, from an end user perspective, this is essentially a web based file system….

  • | | |

    Node Containers

    I feel somewhat ashamed of myself that I’m only now learning about this problem(s) with process shut down with Node & Docker. After finding Bret Fisher’s talk(s) about Node & Docker best practices, I couldn’t believe that there’s a bit of an issue with process signal making it all the way through to the application….

  • |

    React Hooks

    I’d like to keep this post short as I’ve just bought my first house with my girlfriend (I may write a short post about it later), so there’s still boxes everywhere & on top of that I’m still working full time from home, so I’m pretty darn busy to say the very least. Anyway, I…

  • |

    TypeScript DI

    Since it’s been such a long time since I’ve done anything fun, technical or exciting on my personal website, I thought that it would be nice to consider looking at implementing a relatively simplistic IOC solution in TypeScript. I decided to use the more Java oriented approach, whereby I’m using property & class decorators to…

Leave a Reply

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