sendStatusEvent sends connection status event to all channels. If channel is closed, or there is no listener, sendStatusEvent will not block. Lock should be held entering.
(s Status)
| 6555 | // If channel is closed, or there is no listener, sendStatusEvent |
| 6556 | // will not block. Lock should be held entering. |
| 6557 | func (nc *Conn) sendStatusEvent(s Status) { |
| 6558 | Loop: |
| 6559 | for ch := range nc.statListeners[s] { |
| 6560 | // make sure channel is not closed |
| 6561 | select { |
| 6562 | case <-ch: |
| 6563 | // if chan is closed, remove it |
| 6564 | delete(nc.statListeners[s], ch) |
| 6565 | continue Loop |
| 6566 | default: |
| 6567 | } |
| 6568 | // only send event if someone's listening |
| 6569 | select { |
| 6570 | case ch <- s: |
| 6571 | default: |
| 6572 | } |
| 6573 | } |
| 6574 | } |
| 6575 | |
| 6576 | // changeConnStatus changes connections status and sends events |
| 6577 | // to all listeners. Lock should be held entering. |