Friday 23 July 2021

Running multiple task using web worker in Nodejs

I am trying to read multiple JSON files simultaneously and create a single array using the data available in the files and do some processing with the created data array in the Node.js server.

I would like to read these files and do the processing tasks simultaneously using web workers.

I read a few interesting tutorials and articles about the subject, but no one clearly explains how to process simultaneous tasks using web workers.

They talk about running a single separated task from the main thread. But I need to do multiple tasks at once.

I also know that creating multiple workers is not recommended according to the documentation of Node.js.

Maybe I have a misunderstanding of how the web worker is functioning or with the implementation in order to perform multiple tasks.

I also tried this great library Thread.js - https://threads.js.org/ still the documentation is unclear about running multiple tasks.

Can anyone please explain what is the way of implementing this kind of work with best practice along with the pros and cons?

I would prefer implementing the vanilla JS solution other than using a library so the explanation would also be a reference to readers.

Also if possible someone can explain the usage of the Thread.js library as well for future reference.

Thank you very much.



from Running multiple task using web worker in Nodejs

No comments:

Post a Comment