Skip to content

Commit

Permalink
Inlined waitWG() utility function (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
skovtunenko authored Jul 3, 2022
1 parent bb677e6 commit 68ac9d0
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions term.go
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down

0 comments on commit 68ac9d0

Please sign in to comment.