mirror of
https://github.com/libp2p/go-libp2p-resource-manager.git
synced 2025-03-10 17:20:39 +08:00
short circuit write/flush if there are no pending events
This commit is contained in:
parent
83c13993f8
commit
8a60c5d336
8
trace.go
8
trace.go
@ -108,6 +108,10 @@ func (t *trace) background(out io.WriteCloser) {
|
||||
case <-ticker.C:
|
||||
getEvents()
|
||||
|
||||
if len(pend) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := t.writeEvents(pend, jsonOut); err != nil {
|
||||
log.Warnf("error writing rcmgr trace: %s", err)
|
||||
t.mx.Lock()
|
||||
@ -127,6 +131,10 @@ func (t *trace) background(out io.WriteCloser) {
|
||||
case <-t.ctx.Done():
|
||||
getEvents()
|
||||
|
||||
if len(pend) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if err := t.writeEvents(pend, jsonOut); err != nil {
|
||||
log.Warnf("error writing rcmgr trace: %s", err)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user