From aaf59efd205cf62299b13fa30ca3d78f05063a43 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Wed, 16 Nov 2022 22:03:44 -0800 Subject: [PATCH] Expose Done and Err in Shutdown service Signed-off-by: Maksym Pavlenko --- pkg/shutdown/shutdown.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/shutdown/shutdown.go b/pkg/shutdown/shutdown.go index bc1af75ab..12ffac145 100644 --- a/pkg/shutdown/shutdown.go +++ b/pkg/shutdown/shutdown.go @@ -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()