architecture cleanup
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"mxl-player/internal/playback"
|
||||
)
|
||||
|
||||
const playlistReadinessInterval = 10 * time.Millisecond
|
||||
const playlistEventInterval = 10 * time.Millisecond
|
||||
|
||||
var (
|
||||
ErrPlayerPlaybackRequired = errors.New("player playback is required")
|
||||
@@ -18,10 +18,14 @@ var (
|
||||
)
|
||||
|
||||
type playerPlaylist struct {
|
||||
Controller *playback.PlaylistController
|
||||
Coordinator *playback.PlaylistReadinessCoordinator
|
||||
Commands chan playback.PlaylistCommand
|
||||
Readiness chan playback.PlaylistReadiness
|
||||
Controller *playback.PlaylistController
|
||||
|
||||
// commands is written by GUI-facing methods and consumed by Controller.
|
||||
// events is written by coordinator and consumed by Controller. Run owns
|
||||
// both goroutine lifecycles; cancellation replaces channel closing.
|
||||
coordinator *playback.PlaylistEventCoordinator
|
||||
commands chan playback.PlaylistCommand
|
||||
events chan playback.PlaylistEvent
|
||||
}
|
||||
|
||||
func newPlayerPlaylist(
|
||||
@@ -40,7 +44,7 @@ func newPlayerPlaylist(
|
||||
}
|
||||
|
||||
commands := make(chan playback.PlaylistCommand, 32)
|
||||
readiness := make(chan playback.PlaylistReadiness, 8)
|
||||
events := make(chan playback.PlaylistEvent, 8)
|
||||
controller, err := playback.NewPlaylistController(
|
||||
playlist,
|
||||
retry,
|
||||
@@ -49,12 +53,12 @@ func newPlayerPlaylist(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
coordinator, err := playback.NewPlaylistReadinessCoordinator(
|
||||
coordinator, err := playback.NewPlaylistEventCoordinator(
|
||||
controller,
|
||||
player.Controller,
|
||||
player.Status,
|
||||
readiness,
|
||||
playlistReadinessInterval,
|
||||
events,
|
||||
playlistEventInterval,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -62,9 +66,9 @@ func newPlayerPlaylist(
|
||||
|
||||
return &playerPlaylist{
|
||||
Controller: controller,
|
||||
Coordinator: coordinator,
|
||||
Commands: commands,
|
||||
Readiness: readiness,
|
||||
coordinator: coordinator,
|
||||
commands: commands,
|
||||
events: events,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -74,10 +78,10 @@ func (p *playerPlaylist) Run(ctx context.Context) error {
|
||||
|
||||
results := make(chan error, 2)
|
||||
go func() {
|
||||
results <- p.Controller.Run(runCtx, p.Commands, p.Readiness)
|
||||
results <- p.Controller.Run(runCtx, p.commands, p.events)
|
||||
}()
|
||||
go func() {
|
||||
results <- p.Coordinator.Run(runCtx)
|
||||
results <- p.coordinator.Run(runCtx)
|
||||
}()
|
||||
|
||||
first := <-results
|
||||
@@ -121,7 +125,7 @@ func (p *playerPlaylist) Resume() bool {
|
||||
|
||||
func (p *playerPlaylist) enqueue(command playback.PlaylistCommand) bool {
|
||||
select {
|
||||
case p.Commands <- command:
|
||||
case p.commands <- command:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
||||
@@ -104,10 +104,10 @@ func TestNewPlayerPlaylistWiresComponents(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("newPlayerPlaylist() error = %v", err)
|
||||
}
|
||||
if runtime.Controller == nil || runtime.Coordinator == nil {
|
||||
if runtime.Controller == nil || runtime.coordinator == nil {
|
||||
t.Fatalf("runtime components = %#v", runtime)
|
||||
}
|
||||
if runtime.Commands == nil || runtime.Readiness == nil {
|
||||
if runtime.commands == nil || runtime.events == nil {
|
||||
t.Fatalf("runtime channels = %#v", runtime)
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func TestPlayerPlaylistNavigationHelpers(t *testing.T) {
|
||||
if !test.send() {
|
||||
t.Fatal("navigation helper returned false")
|
||||
}
|
||||
if got := <-runtime.Commands; got != test.want {
|
||||
if got := <-runtime.commands; got != test.want {
|
||||
t.Fatalf("navigation command = %#v, want %#v", got, test.want)
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ func TestPlayerPlaylistNavigationQueueFull(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("newPlayerPlaylist() error = %v", err)
|
||||
}
|
||||
for range cap(runtime.Commands) {
|
||||
for range cap(runtime.commands) {
|
||||
if !runtime.Next() {
|
||||
t.Fatal("queue filled before reaching capacity")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user