7 ms·
Workers are awesome but you are right, working with them can be painful without the right tooling. Personally I've written my own libraries for abstracting all
by fabiospampinato 5y ago
Workers are awesome but you are right, working with them can be painful without the right tooling.
Personally I've written my own libraries for abstracting all this away and I'm having a blast working with workers now, maybe check them out:
- WorkTank [1]: This abstracts away the difference between browser workers and Node worker threads, it makes it easy to make worker pools, and it can transfer simple functions to a worker at runtime too.
- WorkTank loader: This abstracts away loading asynchronous function from a worker basically, you just add ".worker" to your file name and that file and all its dependencies are transparently moved to a worker (or worker pool), all the rest of the app (TS types for example) won't even notice anything happened, it just works, transparently.
You might want to check out the more popular "comlink" library too, although it didn't work for me for whatever reason when I tried it, and it doesn't support worker pools I believe.
[1]: https://github.com/fabiospampinato/worktank https://github.com/fabiospampinato/worktank
[2]: https://github.com/fabiospampinato/worktank-loader https://github.com/fabiospampinato/worktank-loader