I have a switch statement inside a goroutine which handles the playback state of audio. The switch statement looks like this (it's controlled with channels)
PlaybackLoop:
// Poll playback status and update current song
select {
case <-next:
if current.next != nil {
current = current.next
break PlaybackLoop
}
case <-prev:
if current.prev != nil {
current = current.prev
}
break PlaybackLoop
case <-done:
return err
default:
time.Sleep(50 * time.Millisecond)
When no channels have inputs, the default
case sleep
s for 50 milliseconds. My justification for this is that I do not to refresh the UI or check media state etc (the stuff that happens in the PlayBackLoop
before the switch statement) unnecessarily.
Is sleeping and appropriate way of making the goroutine more efficient? (by making less checks to the media player state?) Or is this assumptions wholly unfounded, and a simple continue
would suffice?