mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-03 21:33:07 +00:00
don't spawn an extra goroutine for the validator context
This commit is contained in:
parent
145a84a33b
commit
f1be0f1296
@ -38,22 +38,13 @@ func (sub *Subscription) Cancel() {
|
||||
}
|
||||
|
||||
func (sub *Subscription) validateMsg(ctx context.Context, msg *Message) bool {
|
||||
result := make(chan bool, 1)
|
||||
vctx, cancel := context.WithTimeout(ctx, sub.validateTimeout)
|
||||
defer cancel()
|
||||
|
||||
go func() {
|
||||
result <- sub.validate(vctx, msg)
|
||||
}()
|
||||
|
||||
select {
|
||||
case valid := <-result:
|
||||
if !valid {
|
||||
log.Debugf("validation failed for topic %s", sub.topic)
|
||||
}
|
||||
return valid
|
||||
case <-vctx.Done():
|
||||
log.Debugf("validation timeout for topic %s", sub.topic)
|
||||
return false
|
||||
valid := sub.validate(vctx, msg)
|
||||
if !valid {
|
||||
log.Debugf("validation failed for topic %s", sub.topic)
|
||||
}
|
||||
|
||||
return valid
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user