Re: [go-nuts] Managing perpetually running goroutines

2021-09-02 Thread Sanyia Saidova
Awesome, thanks so much for the help here! Learned a lot from the input and code examples. :) Much appreciated! On Thu, 2 Sep 2021, 15:49 Bryan C. Mills, wrote: > On Wed, Sep 1, 2021 at 5:55 PM wrote: > >> Thanks Bryan, especially for the code example. >> >> >> Would using a sync.WaitGroup in

Re: [go-nuts] Managing perpetually running goroutines

2021-09-02 Thread 'Bryan C. Mills' via golang-nuts
On Wed, Sep 1, 2021 at 5:55 PM wrote: > Thanks Bryan, especially for the code example. > > > Would using a sync.WaitGroup in place of the `done` channel in your > example be overkill? Just exploring what’s possible here for my own > education. > Using a `sync.WaitGroup` in place of the `done` ch

Re: [go-nuts] Managing perpetually running goroutines

2021-09-01 Thread Bakul Shah
ent: 31 August 2021 20:22 > To: golang-nuts <mailto:golang-nuts@googlegroups.com> > Subject: Re: [go-nuts] Managing perpetually running goroutines > > For the specific case of managing long-running polling- or pubsub-based > tasks, I would suggest basically the same pattern that

RE: [go-nuts] Managing perpetually running goroutines

2021-09-01 Thread sanyia.saidova
: [go-nuts] Managing perpetually running goroutines For the specific case of managing long-running polling- or pubsub-based tasks, I would suggest basically the same pattern that others on the thread have already given: use a `sync.Map` to associate each task ID with a small struct containing a `context.

Re: [go-nuts] Managing perpetually running goroutines

2021-08-31 Thread 'Bryan C. Mills' via golang-nuts
For the specific case of managing long-running polling- or pubsub-based tasks, I would suggest basically the same pattern that others on the thread have already given: use a `sync.Map` to associate each task ID with a small struct containing a `context.CancelFunc` and a channel that can be used

Re: [go-nuts] Managing perpetually running goroutines

2021-08-30 Thread Brian Candler
For that case, I'd suggest you pass a channel to each worker. It can either close the channel, or send a specific message down it, to indicate its termination. This may also be an X-Y problem. Generally speaking, "worker pools" are an anti-pattern in Go. The startup and termination overhead

Re: [go-nuts] Managing perpetually running goroutines

2021-08-30 Thread Sanyia Saidova
Appreciated, thanks Brian and Ian. On the subject of sync.WaitGroups, I haven't tackled this yet for my use case, but will use the opportunity to brainstorm some options, if that's okay. I want to be able to terminate each worker independently of others (i.e. close on worker, wait for it to finish

Re: [go-nuts] Managing perpetually running goroutines

2021-08-30 Thread Brian Candler
Also: you can use the same context for all the workers (if that's appropriate); or if you want each worker to have a different context, you can make those contexts children of the same top-level context. In that case, you only need to cancel one context and all the workers will stop, without h

Re: [go-nuts] Managing perpetually running goroutines

2021-08-30 Thread Ian Davis
On Sun, 29 Aug 2021, at 10:45 PM, sansaid wrote: > Hello, > > Does anybody know of some reference code or common patterns I can use to keep > track of worker goroutines? For context, I want a user to be able to issue a > "stop" command using a CLI tool which will prompt my server to gracefully

[go-nuts] Managing perpetually running goroutines

2021-08-29 Thread sansaid
Hello, Does anybody know of some reference code or common patterns I can use to keep track of worker goroutines? For context, I want a user to be able to issue a "stop" command using a CLI tool which will prompt my server to gracefully terminate one of my workers. For example, when a user iss