Queue tasks or abort current task and start new task
So I'm just getting my head around a problem I'm having with the useWorker hook. I currently call the worker in a useEffect hook but when the useEffect hook is triggered multiple times while the worker hasn't finished yet I'm getting the following error in the log:
[useWorker] You can only run one instance of the worker at a time, if you want to run more than one in parallel, create another instance with the hook useWorker(). Read more: https://github.com/alewin/useWorker
The problem is I'm no longer interested in the result if the useEffect hook is triggered again so the worker should just abort the current task and start processing the new task. Or if that's not possible I want to queue a task for the worker to process next. Really curious if this can be achieved with the current hook or if I'm overlooking something.
There is a kill method in the controller api, but for me it doesn't kill when the status is PENDING so results may vary
There is an issue with the kill functionality of the library, I have created a fix for the same. Waiting for the maintainers to review and merge the same. https://github.com/alewin/useWorker/pull/122