New to go and to make sure Im on the right page with channels + concurrency I have a struct
type Playlist struct {
playList []*Song
updateList chan *Song
}
I have 2 functions that manipulate the data in separate go routines.
First one is to append data to the playlist whenever a pointer to a song is sent on the channel:
func (p *Playlist) continuousUpdate() {
go func (){
for newSong := range p.updateList {
p.playlist = append(p.playlist, newSong)
}
}()
}
And the second one, every 24 hours a timer will tick, thus resetting the playlist to an empty slice.
func (p *Playlist) controlCurrentPlayList(c <-chan time.Time) {
go func(){
for {
<-c
p.playlist = make([]*Song, 0)
log.Println("Current playlist has reset")
}
}()
}
Do two separate channels handle the synchronization of the data? Or could I very easily run into a race condition?
Ran go build -race
and no errors appeared.