Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reactor API #74

Closed
wants to merge 1 commit into from
Closed

Add Reactor API #74

wants to merge 1 commit into from

Conversation

eNV25
Copy link
Contributor

@eNV25 eNV25 commented Jul 10, 2022

#73

test program:

package main

import (
	"log"
	"time"

	"github.com/fhs/gompd/v2/mpd"
)

func main() {
	r, err := mpd.NewReactor("tcp", "localhost:6600", "", func(c *mpd.Client, intr interface{}, subsystems []string, err error) {
		log.Println(subsystems, intr, err)
		status, err := c.CurrentSong()
		log.Println(status, err)
	})
	if err != nil {
		panic(err)
	}
	defer r.Close()
	t := time.After(5 * time.Second)
	err = r.Interrupt(<-t)
	if err != nil {
		log.Println(err)
	}
	select {}
}

@eNV25 eNV25 mentioned this pull request Jul 10, 2022
@eNV25
Copy link
Contributor Author

eNV25 commented Jul 11, 2022

After trying to implement this and trying to use it, I don't like it. The API is inflexible, and I don't think it's worth the trouble.

I think it would be better to provide safe wrappers to idle and noidle. We could have an idling atomic boolean in Client and use that to disallow all commands other than noidle. Users can then do whatever they want.

In my software, I currently copy gompd using bundle to access the unexported idle and noIdle methods.

https://pkg.go.dev/golang.org/x/tools/cmd/bundle

$ bundle -o mpd_bundle.go github.com/fhs/gompd/v2/mpd

@eNV25 eNV25 closed this Jul 24, 2022
@eNV25 eNV25 deleted the reactor branch October 18, 2022 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant