mirror of https://github.com/go-redis/redis.git
Merge pull request #543 from go-redis/fix/channel-helper
Add Channel helper
This commit is contained in:
commit
3b1a641e2c
20
pubsub.go
20
pubsub.go
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue