Subscribe the client to the specified channels. It returns empty subscription if there are no channels.
(ctx context.Context, channels ...string)
| 230 | // Subscribe the client to the specified channels. It returns |
| 231 | // empty subscription if there are no channels. |
| 232 | func (c *PubSub) Subscribe(ctx context.Context, channels ...string) error { |
| 233 | c.mu.Lock() |
| 234 | defer c.mu.Unlock() |
| 235 | |
| 236 | err := c.subscribe(ctx, "subscribe", channels...) |
| 237 | if c.channels == nil { |
| 238 | c.channels = make(map[string]struct{}) |
| 239 | } |
| 240 | for _, s := range channels { |
| 241 | c.channels[s] = struct{}{} |
| 242 | } |
| 243 | return err |
| 244 | } |
| 245 | |
| 246 | // PSubscribe the client to the given patterns. It returns |
| 247 | // empty subscription if there are no patterns. |