workerize-loader icon indicating copy to clipboard operation
workerize-loader copied to clipboard

enhance README to include ideal use case(s)

Open gpolyn opened this issue 7 years ago • 6 comments

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

gpolyn avatar Apr 29 '18 17:04 gpolyn

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.

developit avatar Apr 30 '18 15:04 developit

Thanks @developit .

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

gpolyn avatar May 01 '18 17:05 gpolyn

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

gpolyn avatar May 02 '18 12:05 gpolyn

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();

developit avatar May 15 '18 15:05 developit

@developit thanks a lot!

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

gpolyn avatar May 19 '18 20:05 gpolyn

Good catch, I updated.

developit avatar May 22 '18 13:05 developit