Go: x/sync: add ordered shutdown package

Created on 25 Oct 2020  路  2Comments  路  Source: golang/go

I built a package that allows to create groups of goroutines on program start and then shut them down in the reverse creation order, group by group. This is very handy to make sure program shuts down cleanly, waiting for all goroutines to finish.

Please have a look at the code https://github.com/ash2k/stager

I've used it in quite a few projects over the years and I thought maybe it'll be useful to the community too. I propose to include it as a package in https://github.com/golang/sync/ repository.

WaitingForInfo

Most helpful comment

shut them down in the reverse creation order [...] waiting for all goroutines to finish

I imagine you could accomplish the same via defers and a synchronization method like a waitgroup, so it's unclear to me that this is truly needed in x/sync. It's entirely fine for people to use the third party package if they so desire. See https://golang.org/doc/faq#x_in_std.

All 2 comments

shut them down in the reverse creation order [...] waiting for all goroutines to finish

I imagine you could accomplish the same via defers and a synchronization method like a waitgroup, so it's unclear to me that this is truly needed in x/sync. It's entirely fine for people to use the third party package if they so desire. See https://golang.org/doc/faq#x_in_std.

Ok, no worries. I just see that errgroup is there and it's even simpler than what I'm suggesting. 馃し

Was this page helpful?
0 / 5 - 0 ratings