Removed one nesting level by removing select statement.
This commit is contained in:
parent
76b3e2e8ad
commit
5c16576fa4
@ -196,33 +196,32 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
mask := <-pw.changed
|
||||||
case mask := <-pw.changed:
|
|
||||||
if mask&syscall.IN_MODIFY > 0 {
|
if mask&syscall.IN_MODIFY > 0 {
|
||||||
lastPlayedCacheMutex.Lock()
|
lastPlayedCacheMutex.Lock()
|
||||||
songs, err := icecastLastPlayedSongs(playlistPath, 1)
|
songs, err := icecastLastPlayedSongs(playlistPath, 1)
|
||||||
if err == nil && len(songs) > 0 {
|
if err == nil && len(songs) > 0 {
|
||||||
CheckAndUpdateMostListenedSong(songs[0], currentlyPlaying)
|
CheckAndUpdateMostListenedSong(songs[0], currentlyPlaying)
|
||||||
if currentlyPlaying.Time == "" {
|
if currentlyPlaying.Time == "" {
|
||||||
currentlyPlaying = songs[0]
|
currentlyPlaying = songs[0]
|
||||||
|
} else {
|
||||||
|
currentlyPlaying.Listeners = songs[0].Listeners
|
||||||
|
if len(lastPlayedCache) == n {
|
||||||
|
lastPlayedCache = append(lastPlayedCache[1:], currentlyPlaying)
|
||||||
} else {
|
} else {
|
||||||
currentlyPlaying.Listeners = songs[0].Listeners
|
lastPlayedCache = append(lastPlayedCache, currentlyPlaying)
|
||||||
if len(lastPlayedCache) == n {
|
|
||||||
lastPlayedCache = append(lastPlayedCache[1:], currentlyPlaying)
|
|
||||||
} else {
|
|
||||||
lastPlayedCache = append(lastPlayedCache, currentlyPlaying)
|
|
||||||
}
|
|
||||||
currentlyPlaying = songs[0]
|
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
currentlyPlaying = songs[0]
|
||||||
log.Println("failed to retrieve last songs:", err)
|
|
||||||
}
|
}
|
||||||
lastPlayedCacheMutex.Unlock()
|
} else if err != nil {
|
||||||
} else if mask&syscall.IN_IGNORED > 0 {
|
log.Println("failed to retrieve last songs:", err)
|
||||||
pw.Close()
|
|
||||||
pw.Watch(playlistPath, n)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
lastPlayedCacheMutex.Unlock()
|
||||||
|
} else if mask&syscall.IN_IGNORED > 0 {
|
||||||
|
pw.Close()
|
||||||
|
pw.Watch(playlistPath, n)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user