Fix deadlock on exit

This commit is contained in:
Junegunn Choi 2021-03-07 21:43:24 +09:00
parent 4c06da8b70
commit f657169616
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -133,6 +133,7 @@ type Terminal struct {
count int
progress int
reading bool
running bool
failed *string
jumping jumpMode
jumpLabels string
@ -505,6 +506,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
ansi: opts.Ansi,
tabstop: opts.Tabstop,
reading: true,
running: true,
failed: nil,
jumping: jumpDisabled,
jumpLabels: opts.JumpLabels,
@ -1843,6 +1845,8 @@ func (t *Terminal) exit(getCode func() int) {
}
// prof.Stop()
t.killPreview(code)
t.running = false
t.mutex.Unlock()
}
// Loop is called to start Terminal I/O
@ -2068,10 +2072,16 @@ func (t *Terminal) Loop() {
go func() {
var focusedIndex int32 = minItem.Index()
var version int64 = -1
for {
running := true
for running {
t.reqBox.Wait(func(events *util.Events) {
defer events.Clear()
t.mutex.Lock()
if !t.running {
running = false
t.mutex.Unlock()
return
}
for req, value := range *events {
switch req {
case reqPrompt: