From 5c16576fa44000316fe893c9835c0b6ced5a68a2 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 21 Aug 2023 06:08:21 +0400 Subject: [PATCH] Removed one nesting level by removing select statement. --- internal/radio/icecast.go | 45 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index 6173057..135abff 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -196,33 +196,32 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) { go func() { for { - select { - case mask := <-pw.changed: - if mask&syscall.IN_MODIFY > 0 { - lastPlayedCacheMutex.Lock() - songs, err := icecastLastPlayedSongs(playlistPath, 1) - if err == nil && len(songs) > 0 { - CheckAndUpdateMostListenedSong(songs[0], currentlyPlaying) - if currentlyPlaying.Time == "" { - currentlyPlaying = songs[0] + mask := <-pw.changed + + if mask&syscall.IN_MODIFY > 0 { + lastPlayedCacheMutex.Lock() + songs, err := icecastLastPlayedSongs(playlistPath, 1) + if err == nil && len(songs) > 0 { + CheckAndUpdateMostListenedSong(songs[0], currentlyPlaying) + if currentlyPlaying.Time == "" { + currentlyPlaying = songs[0] + } else { + currentlyPlaying.Listeners = songs[0].Listeners + if len(lastPlayedCache) == n { + lastPlayedCache = append(lastPlayedCache[1:], currentlyPlaying) } else { - currentlyPlaying.Listeners = songs[0].Listeners - if len(lastPlayedCache) == n { - lastPlayedCache = append(lastPlayedCache[1:], currentlyPlaying) - } else { - lastPlayedCache = append(lastPlayedCache, currentlyPlaying) - } - currentlyPlaying = songs[0] + lastPlayedCache = append(lastPlayedCache, currentlyPlaying) } - } else if err != nil { - log.Println("failed to retrieve last songs:", err) + currentlyPlaying = songs[0] } - lastPlayedCacheMutex.Unlock() - } else if mask&syscall.IN_IGNORED > 0 { - pw.Close() - pw.Watch(playlistPath, n) - return + } else if err != nil { + log.Println("failed to retrieve last songs:", err) } + lastPlayedCacheMutex.Unlock() + } else if mask&syscall.IN_IGNORED > 0 { + pw.Close() + pw.Watch(playlistPath, n) + return } } }()