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.