Skip to content

Commit

Permalink
fix high cpu usage
Browse files Browse the repository at this point in the history
  • Loading branch information
minoic committed Dec 9, 2021
1 parent 4d5d90a commit b4c2073
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions regcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,21 @@ func (this *manager) listen(stream io.Reader, optfuncs ...CommandOption) {
return len(helper[k][i].desc) > len(helper[k][j].desc)
})
}
reader := bufio.NewReader(stream)
bufReader := bufio.NewReader(stream)
for {
var input string
b, _, _ := reader.ReadLine()
input = string(b)
if len(input) == 0 {
continue
}
this.opts.pool <- struct{}{}
go func() {
defer func() {
<-this.opts.pool
b, _, _ := bufReader.ReadLine()
if len(b) != 0 {
this.opts.pool <- struct{}{}
go func() {
defer func() {
<-this.opts.pool
}()
if ret := this.handle(string(b)); len(ret) != 0 {
this.opts.loggerFunc(ret)
}
}()
if ret := this.handle(input); len(ret) != 0 {
this.opts.loggerFunc(ret)
}
}()
} else {
time.Sleep(200 * time.Millisecond)
}
}
}

0 comments on commit b4c2073

Please sign in to comment.