useWorker icon indicating copy to clipboard operation
useWorker copied to clipboard

Queue tasks or abort current task and start new task

Open jordijansen opened this issue 4 years ago • 2 comments

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.

jordijansen avatar Aug 31 '21 13:08 jordijansen

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

onursagir avatar Nov 18 '21 08:11 onursagir

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

ashish-r avatar May 21 '22 07:05 ashish-r