mirror of
https://github.com/peco/peco.git
synced 2026-09-10 07:16:29 -04:00
Merge pull request #759 from peco/fix-resultch-race
fix data race on resultCh in PrintResults
This commit is contained in:
commit
98f51cbbf5
9
peco.go
9
peco.go
|
|
@ -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')
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue