Drain will put a connection into a drain state. All subscriptions will immediately be put into a drain state. Upon completion, the publishers will be drained and can not publish any additional messages. Upon draining of the publishers, the connection will be closed. Use the ClosedCB option to know w
()
| 6180 | // |
| 6181 | // See note in Subscription.Drain for JetStream subscriptions. |
| 6182 | func (nc *Conn) Drain() error { |
| 6183 | nc.mu.Lock() |
| 6184 | if nc.isClosed() { |
| 6185 | nc.mu.Unlock() |
| 6186 | return ErrConnectionClosed |
| 6187 | } |
| 6188 | if nc.isConnecting() || nc.isReconnecting() { |
| 6189 | nc.mu.Unlock() |
| 6190 | nc.Close() |
| 6191 | return ErrConnectionReconnecting |
| 6192 | } |
| 6193 | if nc.isDraining() { |
| 6194 | nc.mu.Unlock() |
| 6195 | return nil |
| 6196 | } |
| 6197 | nc.changeConnStatus(DRAINING_SUBS) |
| 6198 | go nc.drainConnection() |
| 6199 | nc.mu.Unlock() |
| 6200 | |
| 6201 | return nil |
| 6202 | } |
| 6203 | |
| 6204 | // IsDraining tests if a Conn is in the draining state. |
| 6205 | func (nc *Conn) IsDraining() bool { |
no test coverage detected