Handling job cancelation / pool.close
wejick opened this issue · 2 comments
Hi,
I'm still not sure what will happen to the all job when workpool.Close() is invoked and the jobs will react to this. Wondering if there is a way for job to handle cancellation individually from workpool.Close() ?
Or is it possible to do context like cancelation handling inside the job?
ps : tunny is cool
Hey @wejick, when you call Close
there are two actions that occur:
- All workers are told to wake up (if dormant) and close down
- We wait for the workers to finish closing down, which means this call blocks until all pending jobs are completed.
If you want to have workers that are able to quit jobs early in the event of Close
being called then you can implement TunnyInterruptable
, and in the TunnyInterrupt
call you trigger your own mechanism for sending a signal to the TunnyJob
call.
You can alternatively make your own cancellation mechanism outside of the Tunny implementation, but remember to call tunny.Close
after your own mechanism to make sure the goroutines are cleaned up.