don't always spawn a goroutine for sending a new message

This commit is contained in:
vyzo 2018-01-13 20:11:32 +02:00
parent c95ed28496
commit 5ef13c764e
1 changed files with 8 additions and 6 deletions

View File

@ -367,12 +367,14 @@ func (p *PubSub) pushMsg(subs []*Subscription, src peer.ID, msg *Message) {
return
}
go func() {
p.sendMsg <- sendReq{
from: src,
msg: msg,
}
}()
sreq := sendReq{from: src, msg: msg}
select {
case p.sendMsg <- sreq:
default:
go func() {
p.sendMsg <- sreq
}()
}
}
// validate performs validation and only sends the message if all validators succeed