mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-07 15:23:08 +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 {
|
func (sub *Subscription) validateMsg(ctx context.Context, msg *Message) bool {
|
||||||
result := make(chan bool, 1)
|
|
||||||
vctx, cancel := context.WithTimeout(ctx, sub.validateTimeout)
|
vctx, cancel := context.WithTimeout(ctx, sub.validateTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
go func() {
|
valid := sub.validate(vctx, msg)
|
||||||
result <- sub.validate(vctx, msg)
|
if !valid {
|
||||||
}()
|
log.Debugf("validation failed for topic %s", sub.topic)
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return valid
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user