There's not a way to terminate a goroutine. But you can create a context
with cancellation. Each goroutine would need to periodically check
context.Err() and exit on its own.

When you exit, you cancel the context. You could combine this with a
WaitGroup in order to not exit until all other goroutines have completed
(e.g. cancel the context and then await, provided you've added to the wait
group for each task and each one marks their work as done on completion).

----
*Josh Humphries*
jh...@bluegosling.com

On Fri, Aug 18, 2017 at 5:19 PM, <bill.war...@talentinc.com> wrote:

> Thanks to both for replying. Both pieces of advice cover the use case of
> waiting for all goroutines to complete before exiting. I have the opposite
> problem. I want to end all goroutines if I exit. Is there anything in the
> sync package for that?
>
>
> On Friday, August 18, 2017 at 2:40:39 PM UTC-4, Tamás Gulácsi wrote:
>>
>> See golang.org/x/sync/errgroup.WithContext.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to