diff options
author | Hubert Hirtz <hubert@hirtz.pm> | 2021-11-16 09:20:21 +0100 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-11-16 22:22:10 +0100 |
commit | d40d8dc36a608a1349f8353c50c2c71649e6fa75 (patch) | |
tree | d43e01ac710680c5e765e4726ff8928ec2431499 /app.go | |
parent | Don't merge message bounds from multiple networks (diff) |
Allow App.Close() and App.Run() to be run concurrently
Diffstat (limited to 'app.go')
-rw-r--r-- | app.go | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -137,7 +137,11 @@ func NewApp(cfg Config) (app *App, err error) { } func (app *App) Close() { - app.win.Close() + app.win.Exit() // tell all instances of app.ircLoop to stop when possible + app.events <- event{ // tell app.eventLoop to stop + src: "*", + content: nil, + } for _, session := range app.sessions { session.Close() } @@ -166,6 +170,8 @@ func (app *App) CurrentBuffer() (netID, buffer string) { // eventLoop retrieves events (in batches) from the event channel and handle // them, then draws the interface after each batch is handled. func (app *App) eventLoop() { + defer app.win.Close() + evs := make([]event, 0, eventChanSize) for !app.win.ShouldExit() { ev := <-app.events @@ -181,7 +187,17 @@ func (app *App) eventLoop() { } } - app.handleEvents(evs) + for _, ev := range evs { + if ev.src == "*" { + if ev.content == nil { + return + } + app.handleUIEvent(ev.content) + } else { + app.handleIRCEvent(ev.src, ev.content) + } + } + if !app.pasting { app.setStatus() app.updatePrompt() @@ -255,6 +271,9 @@ func (app *App) ircLoop(netID string) { HeadColor: tcell.ColorRed, Body: ui.PlainString("Connection lost"), }) + if app.win.ShouldExit() { + break + } time.Sleep(10 * time.Second) } } @@ -340,17 +359,6 @@ func (app *App) uiLoop() { } } -// handleEvents handles a batch of events. -func (app *App) handleEvents(evs []event) { - for _, ev := range evs { - if ev.src == "*" { - app.handleUIEvent(ev.content) - } else { - app.handleIRCEvent(ev.src, ev.content) - } - } -} - func (app *App) handleUIEvent(ev interface{}) { switch ev := ev.(type) { case *tcell.EventResize: |