Subscribe creates a subscription for the given client. An error will be returned to the caller if the context is canceled or if subscription already exist for pair clientID and query. outCapacity can be used to set a capacity for Subscription#Out channel (1 by default). Panics if outCapacity is le
( ctx context.Context, clientID string, query Query, outCapacity ...int)
| 147 | // default). Panics if outCapacity is less than or equal to zero. If you want |
| 148 | // an unbuffered channel, use SubscribeUnbuffered. |
| 149 | func (s *Server) Subscribe( |
| 150 | ctx context.Context, |
| 151 | clientID string, |
| 152 | query Query, |
| 153 | outCapacity ...int) (*Subscription, error) { |
| 154 | outCap := 1 |
| 155 | if len(outCapacity) > 0 { |
| 156 | if outCapacity[0] <= 0 { |
| 157 | panic("Negative or zero capacity. Use SubscribeUnbuffered if you want an unbuffered channel") |
| 158 | } |
| 159 | outCap = outCapacity[0] |
| 160 | } |
| 161 | |
| 162 | return s.subscribe(ctx, clientID, query, outCap) |
| 163 | } |
| 164 | |
| 165 | // SubscribeUnbuffered does the same as Subscribe, except it returns a |
| 166 | // subscription with unbuffered channel. Use with caution as it can freeze the |