Wrap queue+message pair into Result
This commit is contained in:
parent
557b1da99f
commit
3adaa805eb
@ -2,22 +2,26 @@ package hub
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Subscription struct {
|
Subscription struct {
|
||||||
queues []string
|
Queues []string
|
||||||
result chan<- []byte
|
result chan<- Result
|
||||||
done chan struct{}
|
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{
|
return &Subscription{
|
||||||
queues: queues,
|
Queues: queues,
|
||||||
result: result,
|
result: result,
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Subscription) Need(queue string) bool {
|
func (s *Subscription) Need(queue string) bool {
|
||||||
for _, q := range s.queues {
|
for _, q := range s.Queues {
|
||||||
if q == queue {
|
if q == queue {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -26,7 +30,7 @@ func (s *Subscription) Need(queue string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Subscription) Send(msg []byte) bool {
|
func (s *Subscription) Send(res Result) bool {
|
||||||
success := make(chan bool)
|
success := make(chan bool)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -36,7 +40,7 @@ func (s *Subscription) Send(msg []byte) bool {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
s.result <- msg
|
s.result <- res
|
||||||
success <- true
|
success <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user