Skip to content

Commit

Permalink
Add Channel helper
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Apr 11, 2017
1 parent 2e49447 commit 34ea5f9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,26 @@ func (c *PubSub) resubscribe() {
}
}

// Channel returns a channel for concurrently receiving messages.
// The channel is closed with PubSub.
func (c *PubSub) Channel() <-chan *Message {
ch := make(chan *Message, 100)
go func() {
for {
msg, err := c.ReceiveMessage()
if err != nil {
if err == pool.ErrClosed {
break
}
continue
}
ch <- msg
}
close(ch)
}()
return ch
}

func remove(ss []string, es ...string) []string {
if len(es) == 0 {
return ss[:0]
Expand Down

0 comments on commit 34ea5f9

Please sign in to comment.