package mpd import ( "image" "github.com/sirupsen/logrus" "go.maze.io/harmon/player" ) type artRequest struct { Path string Art chan image.Image } func (d *Player) AlbumArt(track *player.Track) (image.Image, bool) { if track == nil || track.Path == "" { return nil, false } if cached, ok := d.artCache.Load(track.Path); ok { return cached.(image.Image), true } // Not in cache, request artwork through the art connection. art := make(chan image.Image) d.artRequest <- &artRequest{Path: track.Path, Art: art} // Respond with image. if image := <-art; image != nil { return image, true } return nil, false } func (d *Player) artLoop(conn *clientConn) { for { select { case request := <-d.artRequest: logrus.WithField("path", request.Path).Debug("requesting album art") request.Art <- nil case <-d.quit: return } } }