Open gpolyn opened 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.
Thanks @developit .
(FYI - there is a pending issue with clooneyjs
dependency, comlink
at https://github.com/GoogleChromeLabs/comlink/issues/63.)
FWIW, here's an example of pooling with workerize-loader
: https://github.com/gpolyn/react-and-workerize-loader/blob/master/src/workerPool2.js.
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 thanks a lot!
Your mod revised at line 33: https://gist.github.com/gpolyn/9a2ced1e6f4f12375f7430cfcc2ba6b6
Good catch, I updated.
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