Merge pull request #759 from peco/fix-resultch-race

fix data race on resultCh in PrintResults
This commit is contained in:
lestrrat 2026-02-20 22:29:51 +09:00 committed by GitHub
commit 98f51cbbf5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1086,11 +1086,12 @@ func (p *Peco) PrintResults() {
selection.Add(l)
}
}
p.SetResultCh(make(chan line.Line))
resultCh := make(chan line.Line)
p.SetResultCh(resultCh)
go func() {
defer close(p.resultCh)
defer close(resultCh)
p.selection.Ascend(func(l line.Line) bool {
p.ResultCh() <- l
resultCh <- l
return true
})
}()
@ -1104,7 +1105,7 @@ func (p *Peco) PrintResults() {
buf.WriteString(p.Query().String())
buf.WriteByte('\n')
}
for line := range p.ResultCh() {
for line := range resultCh {
buf.WriteString(line.Output())
buf.WriteByte('\n')
}