From 3adaa805eb08eea602e5ffbca14e9b109ca5df4a Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Thu, 11 Sep 2014 14:27:48 +0400 Subject: [PATCH] Wrap queue+message pair into Result --- hub/subscription.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/hub/subscription.go b/hub/subscription.go index e529503..14ffe47 100644 --- a/hub/subscription.go +++ b/hub/subscription.go @@ -2,22 +2,26 @@ package hub type ( Subscription struct { - queues []string - result chan<- []byte + Queues []string + result chan<- Result done chan struct{} } + Result struct { + Queue string + Message []byte + } ) -func NewSubscription(queues []string, result chan<- []byte) *Subscription { +func NewSubscription(queues []string, result chan<- Result) *Subscription { return &Subscription{ - queues: queues, + Queues: queues, result: result, done: make(chan struct{}), } } func (s *Subscription) Need(queue string) bool { - for _, q := range s.queues { + for _, q := range s.Queues { if q == queue { return true } @@ -26,7 +30,7 @@ func (s *Subscription) Need(queue string) bool { return false } -func (s *Subscription) Send(msg []byte) bool { +func (s *Subscription) Send(res Result) bool { success := make(chan bool) go func() { @@ -36,7 +40,7 @@ func (s *Subscription) Send(msg []byte) bool { } }() - s.result <- msg + s.result <- res success <- true }()