alitto / pond

🔘 Minimalistic and High-performance goroutine worker pool written in Go
MIT License
1.43k stars 60 forks source link

error handling #29

Closed caevv closed 2 years ago

caevv commented 2 years ago

Any way to submit a task and when an error happens, stop other workers? Kind of like errgroup.

alitto commented 2 years ago

Hey @caevv, pond doesn't support that pattern at the moment, but it might be a good addition

leonhandl3r commented 2 years ago

@alitto @caevv how golang can stop goroutines from another? We can not do it. I think it is popular to stop submit similar task to group of workers when an error from a worker which is running kind of this task

caevv commented 2 years ago

You stop accepting new tasks. Check example usage here: https://cs.opensource.google/go/x/sync/+/036812b2:errgroup/errgroup.go

alitto commented 2 years ago

Hey @caevv, I just released v1.8.0 of pond and added a new API to support a functionality similar to what errgroup provides. Please check it out at https://github.com/alitto/pond#submitting-a-group-of-tasks-associated-to-a-context-since-v180 and let me know your thoughts. As soon as one of the tasks returns a non-nil error, the remaining tasks are cancelled and never started. Also, a context.Context can be specified to allow cancelation of tasks.