Unsubscribe will remove interest in the given subject. For a JetStream subscription, if the library has created the JetStream consumer, it will send a DeleteConsumer request to the server (if the unsubscribe itself was successful). If the delete operation fails, the error will be returned. If you d
()
| 5179 | // create the consumer with AddConsumer and bind to this consumer (using |
| 5180 | // the nats.Bind() option). |
| 5181 | func (s *Subscription) Unsubscribe() error { |
| 5182 | if s == nil { |
| 5183 | return ErrBadSubscription |
| 5184 | } |
| 5185 | s.mu.Lock() |
| 5186 | conn := s.conn |
| 5187 | closed := s.closed |
| 5188 | dc := s.jsi != nil && s.jsi.dc |
| 5189 | s.mu.Unlock() |
| 5190 | if conn == nil || conn.IsClosed() { |
| 5191 | return ErrConnectionClosed |
| 5192 | } |
| 5193 | if closed { |
| 5194 | return ErrBadSubscription |
| 5195 | } |
| 5196 | if conn.IsDraining() { |
| 5197 | return ErrConnectionDraining |
| 5198 | } |
| 5199 | err := conn.unsubscribe(s, 0, false) |
| 5200 | if err == nil && dc { |
| 5201 | err = s.deleteConsumer() |
| 5202 | } |
| 5203 | return err |
| 5204 | } |
| 5205 | |
| 5206 | // checkDrained will watch for a subscription to be fully drained |
| 5207 | // and then remove it. |