GoogleChromeLabs / GoogleChromeLabs/comlink
Worker Pool for similar tasks
- Dominant language
- TypeScript
- Stars
- 12.8k
- Forks
- 435
- PR merge metrics
- No merged PRs in 30d
Description
I would like to use a worker pool to delegate tasks to multiple workers with the same interface.
Without Comlink: When there is a new task to be done, the pool selects a worker that is currently idle and assigns the task to it. For the time a worker is processing a task i mark the worker as "busy" - if the work is done i mark the worker as idle. Its working fine but i need to write my own message protocol ending up writing long switch-case statements
With Comlink: The idea is to request a "free" worker from the worker pool (using a Promise), execute an async function, and process the result in the form of a return value. I can mark the requested worker as "busy" but i have problems mark is as "idle" after returning the value.
Unfortunately, I have not found a way to determine whether or how many "messages" are currently being processed by a worker. So, whether a function is currently being executed via Comlink.
Do you have any idea on how I could solve the problem?
Contributor guide
Assessment
This issue has not been assessed yet.