From 68ac9d02acb5016050e9be9d4ddda7eaae76cecf Mon Sep 17 00:00:00 2001 From: Sergio Kovtunenko Date: Sun, 3 Jul 2022 19:43:35 +0300 Subject: [PATCH] Inlined `waitWG()` utility function (#31) --- term.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/term.go b/term.go index 83f39f5..99b22f2 100644 --- a/term.go +++ b/term.go @@ -110,7 +110,11 @@ func (s *Stopper) Wait(appCtx context.Context, timeout time.Duration) error { <-appCtx.Done() - wgChan := waitWG(s.wg) + wgChan := make(chan struct{}) + go func() { + defer close(wgChan) + s.wg.Wait() + }() select { case <-time.After(timeout): @@ -120,18 +124,6 @@ func (s *Stopper) Wait(appCtx context.Context, timeout time.Duration) error { } } -// waitWG returns a chan that will be closed once given wg is done. -func waitWG(wg *sync.WaitGroup) <-chan struct{} { - ch := make(chan struct{}) - - go func() { - defer close(ch) - wg.Wait() - }() - - return ch -} - // waitShutdown waits for the context to be done and then sequentially notifies existing shutdown hooks. func (s *Stopper) waitShutdown(appCtx context.Context) { defer s.wg.Done()