mirror of
https://github.com/peco/peco.git
synced 2026-09-15 09:46:17 -04:00
Move the fail-safe notify sync.Once call to a defer, so we don't have to remember calling it
This commit is contained in:
parent
bf00034e15
commit
82a9d29697
11
source.go
11
source.go
|
|
@ -75,6 +75,12 @@ func (s *Source) Setup(ctx context.Context, state *Peco) {
|
|||
state.Hub().SendStatusMsg("")
|
||||
close(s.ready)
|
||||
}
|
||||
|
||||
// Register this to be called in a defer, just in case we could bailed
|
||||
// out without reading a single line.
|
||||
// Note: this will be a no-op if notify.Do has been called before
|
||||
defer notify.Do(notifycb)
|
||||
|
||||
scanner := bufio.NewScanner(s.in)
|
||||
defer func() {
|
||||
if util.IsTty(s.in) {
|
||||
|
|
@ -102,7 +108,6 @@ func (s *Source) Setup(ctx context.Context, state *Peco) {
|
|||
if pdebug.Enabled {
|
||||
pdebug.Printf("Bailing out of source setup, because ctx was canceled")
|
||||
}
|
||||
notify.Do(notifycb)
|
||||
return
|
||||
case l, ok := <-lines:
|
||||
if !ok {
|
||||
|
|
@ -117,10 +122,6 @@ func (s *Source) Setup(ctx context.Context, state *Peco) {
|
|||
notify.Do(notifycb)
|
||||
}
|
||||
}
|
||||
// Call this after the for loop, just in case scanner.Scan()
|
||||
// did not return a single line.
|
||||
// Note: this will be a no-op if notify.Do has been called before
|
||||
notify.Do(notifycb)
|
||||
|
||||
if pdebug.Enabled {
|
||||
pdebug.Printf("Read all %d lines from source", readCount)
|
||||
|
|
|
|||
Loading…
Reference in a new issue