1
0
Fork 0

Rename result into message

This commit is contained in:
Gregory Eremin 2014-09-24 16:52:31 +04:00
parent 424dacae5b
commit d74792a591
2 changed files with 8 additions and 8 deletions

View File

@ -35,7 +35,7 @@ func (h *Hub) Pub(queue string, msg []byte) bool {
default: default:
} }
if ok := s.Send(Result{queue, msg}); ok { if ok := s.Send(Message{queue, msg}); ok {
return true return true
} }
} }
@ -49,7 +49,7 @@ func (h *Hub) Pub(queue string, msg []byte) bool {
func (h *Hub) Sub(s *Subscription) { func (h *Hub) Sub(s *Subscription) {
for _, q := range s.Queues { for _, q := range s.Queues {
if msg, ok := h.storage.Get(q); ok { if msg, ok := h.storage.Get(q); ok {
s.Send(Result{q, msg}) s.Send(Message{q, msg})
return return
} }
} }

View File

@ -3,10 +3,10 @@ package hub
type ( type (
Subscription struct { Subscription struct {
Queues []string Queues []string
result chan Result result chan Message
done chan struct{} done chan struct{}
} }
Result struct { Message struct {
Queue string Queue string
Message []byte Message []byte
} }
@ -15,7 +15,7 @@ type (
func NewSubscription(queues []string) *Subscription { func NewSubscription(queues []string) *Subscription {
return &Subscription{ return &Subscription{
Queues: queues, Queues: queues,
result: make(chan Result), result: make(chan Message),
done: make(chan struct{}), done: make(chan struct{}),
} }
} }
@ -30,7 +30,7 @@ func (s *Subscription) Need(queue string) bool {
return false return false
} }
func (s *Subscription) Send(res Result) bool { func (s *Subscription) Send(msg Message) bool {
success := make(chan bool) success := make(chan bool)
go func() { go func() {
@ -40,14 +40,14 @@ func (s *Subscription) Send(res Result) bool {
} }
}() }()
s.result <- res s.result <- msg
success <- true success <- true
}() }()
return <-success return <-success
} }
func (s *Subscription) Result() <-chan Result { func (s *Subscription) Result() <-chan Message {
return s.result return s.result
} }