Closed riskers closed 8 months ago
I thought it would be possible to execute multiple tasks in multiple workers at the same time and then aggregate the results, like fork join.
The core feature of workerpool
is that you can execute multiple tasks in parallel, a nice example to try this out is examples/browser/dedicatedWorker.html. If you have a big task that you can split in smaller parts, you can indeed execute the subtasks in parallel and in the end aggregate the results like in your example, you last example with the await Promise.all
should indeed work.
why is there always only one worker execute?
That is not the case.
codesandbox There is only a second worker executing
workerpool
only creates more workers when needed: when a new task is added whilst all created workers are busy (and maxWorkers
isn't reached). The tasks in your example take about no time, so I guess that case does not happen in your example. To see more workers being created, change your tasks to something that takes say 10 seconds (for example return a Promise that resolves after 10 seconds using a setTimeout
).
Oh, I see.
Thank you for your patience 😄
It's a wonderful lib for workers!
But Can / How it assign task to workers?
SandboxCode ->
I see that
workerpool.pool
is executed and 3 workers are created:There is always only one worker executing when I clicked button:
Can each worker perform the task equally?
Because now I have an application scenario:
But only one worker is executing the task. Am I using it wrong?
I thought it would be possible to execute multiple tasks in multiple workers at the same time and then aggregate the results, like fork join.