diff --git a/main.go b/main.go index cf618f0..e8f9afe 100644 --- a/main.go +++ b/main.go @@ -73,7 +73,7 @@ func main() { g.SetManagerFunc(vm.Layout) // Start RPC calling routine - go peers.Fetch(g) + go peers.FetchLoop(g) if err := g.MainLoop(); err != nil && err != gocui.ErrQuit { log.Panicln(err) diff --git a/peers.go b/peers.go index 243b9ab..66459c4 100644 --- a/peers.go +++ b/peers.go @@ -22,23 +22,28 @@ func NewPeersState(host string, port int) *PeersState { return &PeersState{c: c} } -func (p *PeersState) Fetch(g *gocui.Gui) { +func (p *PeersState) FetchLoop(g *gocui.Gui) { for { select { case <-threadDone: return default: - peers, err := p.c.getPeers() - if err != nil { - log.Panicln(err) - } - p.list = peers + peers := p.Fetch() writePeers(g, peers) } <-time.After(interval * time.Second) } } +func (p *PeersState) Fetch() []Peer { + peers, err := p.c.getPeers() + if err != nil { + log.Panicln(err) + } + p.list = peers + return peers +} + func writePeers(g *gocui.Gui, peers []Peer) { g.Update(func(g *gocui.Gui) error { v, err := g.View("main")