You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The last comment mentions using an interface in the old pull request. I liked the idea and I want to implement it.
Here's how I'm imagining it would look like:
// Reactor represents an MPD connection that reacts to events.typeReactorstruct{ ... }
// NewReactor connects to MPD and reacts to events. Set handlers and other options// by passing ReactorOptions.funcNewReactor(network, addr, passwordstring, options...ReactorOption) *Reactor// Subsystems restricts subsystems watched for.func (r*Reactor) Subsystems(subsystems...string)
// Interrupt stops watching for event temporarily and runs the interrupt handler with args.func (r*Reactor) Interrupt(args...interface{})
// ReactorOptiontypeReactorOptionfunc(r*Reactor)
// ReactorSubsystems restricts the subsystems watched for.funcReactorSubsystems(subsystems...string) ReactorOption// ReactorEventHandler is run for each change in MPD. The first argument is the subsystem// that changed. See the list of subsystems:// https://mpd.readthedocs.io/en/stable/protocol.html#command-idlefuncReactorEventHandler(ffunc(c*Client, subsystemstring)) ReactorOptionfuncReactorErrorHandler(ffunc(c*Client, errerror)) ReactorOptionfuncReactorInterruptHandler(ffunc(c*Client, args...interface{})) ReactorOption
Instead of an interface, this uses the functional options pattern. This makes the API easier to use and makes any or all functionality optional.
This also adds an interrupt system, which allows using Client for external events. Interrupt will simply call noidle and send args on a channel.
We could also add ReactorOptions that send on a channel, so Watcher could be implemented in terms of Reactor.
The text was updated successfully, but these errors were encountered:
From #22.
The last comment mentions using an interface in the old pull request. I liked the idea and I want to implement it.
Here's how I'm imagining it would look like:
Instead of an interface, this uses the functional options pattern. This makes the API easier to use and makes any or all functionality optional.
This also adds an interrupt system, which allows using
Client
for external events. Interrupt will simply callnoidle
and sendargs
on a channel.We could also add
ReactorOption
s that send on a channel, soWatcher
could be implemented in terms ofReactor
.The text was updated successfully, but these errors were encountered: