From bc6ad1608c37b56aa031760cc07e9a30ebe030d8 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Tue, 14 Jul 2015 09:14:51 -0700 Subject: [PATCH] Don't use time.After if there is no timeout Signed-off-by: Alexander Morozov --- pkg/pubsub/publisher.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/pubsub/publisher.go b/pkg/pubsub/publisher.go index 6f3d5924d..ab457cfba 100644 --- a/pkg/pubsub/publisher.go +++ b/pkg/pubsub/publisher.go @@ -58,9 +58,16 @@ func (p *Publisher) Publish(v interface{}) { p.m.RLock() for sub := range p.subscribers { // send under a select as to not block if the receiver is unavailable + if p.timeout > 0 { + select { + case sub <- v: + case <-time.After(p.timeout): + } + continue + } select { case sub <- v: - case <-time.After(p.timeout): + default: } } p.m.RUnlock()