Merge pull request #7686 from mxpv/shutdown

Expose Done and Err in Shutdown service
This commit is contained in:
Maksym Pavlenko 2022-11-17 16:17:30 -08:00 committed by GitHub
commit 1a0ac21e20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,6 +37,11 @@ type Service interface {
// the shutdown channel is closed. A callback error will propagate to the
// context error
RegisterCallback(func(context.Context) error)
// Done returns a channel that's closed when all shutdown callbacks are invoked.
Done() <-chan struct{}
// Err returns nil if Done is not yet closed.
// If Done is closed, Err returns first failed callback error or ErrShutdown.
Err() error
}
// WithShutdown returns a context which is similar to a cancel context, but
@ -99,6 +104,7 @@ func (s *shutdownService) Err() error {
defer s.mu.Unlock()
return s.err
}
func (s *shutdownService) RegisterCallback(fn func(context.Context) error) {
s.mu.Lock()
defer s.mu.Unlock()