Skip to content

Commit

Permalink
fix(player): More effectively cancel timeouts when changing play state
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Sep 15, 2023
1 parent cda48fd commit 536c90e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions internal/movie/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,13 @@ func (p *Player) OptionsView() string {
}

func (p *Player) pause() tea.Cmd {
p.playCancel()
p.clearTimeouts()
p.timeoutCtx, p.timeoutCancel = context.WithCancel(context.Background())
return tick(p.timeoutCtx, 15*time.Minute, Quit())
}

func (p *Player) play() tea.Cmd {
if p.timeoutCancel != nil {
p.timeoutCancel()
}
p.clearTimeouts()
p.playCtx, p.playCancel = context.WithCancel(context.Background())
return func() tea.Msg {
return frameTickMsg{}
Expand All @@ -235,3 +233,12 @@ func (p *Player) play() tea.Cmd {
func (p Player) isPlaying() bool {
return p.playCtx.Err() == nil
}

func (p *Player) clearTimeouts() {
if p.playCancel != nil {
p.playCancel()
}
if p.timeoutCancel != nil {
p.timeoutCancel()
}
}

0 comments on commit 536c90e

Please sign in to comment.