Skip to content

Commit

Permalink
try to optimize selectgo
Browse files Browse the repository at this point in the history
  • Loading branch information
Termina1 committed Sep 23, 2024
1 parent d2ea338 commit 75cce18
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions protocol/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,28 @@ func (p *Peer) keepRead(ctx context.Context) error {
time := time.After(p.readAccumtTimeLimit)
var buff Records
for len(buff) <= p.readBatchSize {
select {
case <-time:
break
case <-ctx.Done():
if len(time) > 0 || ctx.Err() != nil {
break
case recs, ok := <-reading:
// closed
}
if len(reading) > 0 {
recs, ok := <-reading
if !ok {
break
}
buff = append(buff, recs...)
} else {
select {
case <-time:
break
case <-ctx.Done():
break
case recs, ok := <-reading:
// closed
if !ok {
break
}
buff = append(buff, recs...)
}
}
}
if err := p.inout.Drain(ctx, buff); err != nil {
Expand Down

0 comments on commit 75cce18

Please sign in to comment.