MCPcopy
hub / github.com/nats-io/nats.go / Drain

Method Drain

nats.go:6182–6202  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

6180//
6181// See note in Subscription.Drain for JetStream subscriptions.
6182func (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.
6205func (nc *Conn) IsDraining() bool {

Callers 1

drainConnectionMethod · 0.95

Calls 7

isClosedMethod · 0.95
isConnectingMethod · 0.95
isReconnectingMethod · 0.95
CloseMethod · 0.95
isDrainingMethod · 0.95
changeConnStatusMethod · 0.95
drainConnectionMethod · 0.95

Tested by

no test coverage detected