1
0
Fork 0

Wrap queue+message pair into Result

This commit is contained in:
Gregory Eremin 2014-09-11 14:27:48 +04:00
parent 557b1da99f
commit 3adaa805eb
1 changed files with 11 additions and 7 deletions

View File

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