Cleanup: Worker, simplify Listerer.Run() function

No functional changes, except that now the "listener shutting down"
message will also be logged in case of a panic.
This commit is contained in:
Sybren A. Stüvel 2022-06-26 13:32:15 +02:00
parent f244355328
commit 34f1cc076c

View File

@ -46,20 +46,17 @@ func NewListener(client FlamencoClient, buffer UpstreamBuffer) *Listener {
} }
func (l *Listener) Run(ctx context.Context) { func (l *Listener) Run(ctx context.Context) {
keepRunning := true defer l.doneWg.Done()
for keepRunning { defer log.Debug().Msg("listener shutting down")
for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
keepRunning = false return
continue
case <-time.After(10 * time.Second): case <-time.After(10 * time.Second):
// This is just a dummy thing. log.Trace().Msg("listener is still running")
} }
log.Trace().Msg("listener is still running")
} }
log.Debug().Msg("listener shutting down")
l.doneWg.Done()
} }
func (l *Listener) Wait() { func (l *Listener) Wait() {