StatusChanged returns a channel on which given list of connection status changes will be reported. If no statuses are provided, defaults will be used: CONNECTED, RECONNECTING, DISCONNECTED, CLOSED.
(statuses ...Status)
| 6504 | // StatusChanged returns a channel on which given list of connection status changes will be reported. |
| 6505 | // If no statuses are provided, defaults will be used: CONNECTED, RECONNECTING, DISCONNECTED, CLOSED. |
| 6506 | func (nc *Conn) StatusChanged(statuses ...Status) chan Status { |
| 6507 | if len(statuses) == 0 { |
| 6508 | statuses = []Status{CONNECTED, RECONNECTING, DISCONNECTED, CLOSED} |
| 6509 | } |
| 6510 | ch := make(chan Status, 10) |
| 6511 | nc.mu.Lock() |
| 6512 | defer nc.mu.Unlock() |
| 6513 | for _, s := range statuses { |
| 6514 | nc.registerStatusChangeListener(s, ch) |
| 6515 | } |
| 6516 | return ch |
| 6517 | } |
| 6518 | |
| 6519 | // RemoveStatusListener removes a status change listener. |
| 6520 | // If the channel is not closed, it will be closed. |