developit / workerize-loader

🏗️ Automatically move a module into a Web Worker (Webpack loader)
https://npm.im/workerize-loader
2.31k stars 86 forks source link

enhance README to include ideal use case(s) #36

Open gpolyn opened 6 years ago

gpolyn commented 6 years ago

I came to workerize-loader for ease-of-use, but now I wonder about about pooling-type issues imposed by my present need for overlapping tasks.

So, I hope this is a helpful suggestion: Clarify use case in README, e.g., greenlet < workerize-loader < workerpool.

For example, does the following feature imply a 'natural' way to limit the number of workers?

     If exported module methods are already async, signature is unchanged

developit commented 6 years ago

In the case of workerize and greenlet, no pooling is supported. For those use-cases, I'd recommend Clooney since it has built-in strategies for pooling. I'm going to update the readme to point people towards that library for such use-cases.

gpolyn commented 6 years ago

Thanks @developit .

(FYI - there is a pending issue with clooneyjs dependency, comlink at https://github.com/GoogleChromeLabs/comlink/issues/63.)

gpolyn commented 6 years ago

FWIW, here's an example of pooling with workerize-loader: https://github.com/gpolyn/react-and-workerize-loader/blob/master/src/workerPool2.js.

developit commented 6 years ago

Hi @gpolyn - there's some extra stuff going on in that file that you can get rid of when using Workerize. Here's a modified version: https://gist.github.com/developit/65a2212731f6b00a8aaa55d70c594f5c

Perk: you can just call your exported functions on the pool, no need for the .queueJob(name) stuff:

import Worker from 'workerize-loader!./worker';
import WorkerPool from './worker-pool';
let pool = new WorkerPool(Worker, 4);
for (let i=10; i--; ) pool.doThing();
gpolyn commented 6 years ago

@developit thanks a lot!

Your mod revised at line 33: https://gist.github.com/gpolyn/9a2ced1e6f4f12375f7430cfcc2ba6b6

developit commented 6 years ago

Good catch, I updated.