sourcegraph / conc

Better structured concurrency for go

Home Page:https://about.sourcegraph.com/blog/building-conc-better-structured-concurrency-for-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exit on the first error encountered

houbaron opened this issue · comments

When we run batch tasks, sometimes an error in one subtask means that the whole task is wrong. So it is desirable to add the ability to exit on the first error encountered.

Would (*ContextPool).CancelOnError() work for your use case? When a task returns an error, the context is canceled, signaling to your tasks that they should exit.

I'm hesitant to break the current guarantee that "all tasks spawned with Go() will be run to completion." I'd prefer to leave the definition of "completion" to the user.