From 2ab93e68bd7c28dd6b673b31605264d7a1e26efc Mon Sep 17 00:00:00 2001 From: Cenk Alti Date: Tue, 19 Feb 2019 23:23:43 +0300 Subject: [PATCH] fix stuck details in console screen --- internal/console/console.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/console/console.go b/internal/console/console.go index ec65e198..128393f8 100644 --- a/internal/console/console.go +++ b/internal/console/console.go @@ -40,8 +40,8 @@ type Console struct { func New(clt *rainrpc.Client) *Console { return &Console{ client: clt, - updateTorrentsC: make(chan struct{}), - updateDetailsC: make(chan struct{}), + updateTorrentsC: make(chan struct{}, 1), + updateDetailsC: make(chan struct{}, 1), } } @@ -171,19 +171,20 @@ func (c *Console) drawDetails(g *gocui.Gui) error { } func (c *Console) updateLoop(g *gocui.Gui) { - c.updateTorrents(g) - c.updateDetails(g) - ticker := time.NewTicker(time.Second) + defer ticker.Stop() + + c.triggerUpdateTorrents() for { + select { case <-ticker.C: - c.updateTorrents(g) - c.updateDetails(g) + c.triggerUpdateTorrents() + c.triggerUpdateDetails() case <-c.updateTorrentsC: c.updateTorrents(g) case <-c.updateDetailsC: - c.updateDetails(g) + go c.updateDetails(g) } } } @@ -253,8 +254,11 @@ func (c *Console) updateDetails(g *gocui.Gui) { } c.m.Lock() + defer c.m.Unlock() c.updatingDetails = false - c.m.Unlock() + if selectedID != c.selectedID { + return + } g.Update(c.drawDetails) }