don't spawn an extra goroutine for the validator context

This commit is contained in:
vyzo 2018-01-13 22:14:01 +02:00
parent 145a84a33b
commit f1be0f1296
1 changed files with 5 additions and 14 deletions

View File

@ -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
}