channel.go
func (ch *Channel) Close() {
	ch.Logger().Info("Channel.Close called.")
	var connections []*Connection
	var channelClosed bool

	func() {
		ch.mutable.Lock()
		defer ch.mutable.Unlock()

		if ch.mutable.state == ChannelClosed {
			ch.Logger().Info("Channel already closed, skipping additional Close() calls")
			return
		}

		if ch.mutable.l != nil {
			ch.mutable.l.Close()
		}

		// Stop the idle connections timer.
		ch.mutable.idleSweep.Stop()

		ch.mutable.state = ChannelStartClose
		if len(ch.mutable.conns) == 0 {
			ch.mutable.state = ChannelClosed
			channelClosed = true
		}
		for _, c := range ch.mutable.conns {
			connections = append(connections, c)
		}
	}()

	for _, c := range connections {
		c.close(LogField{"reason", "channel closing"})
	}

	if channelClosed {
		ch.onClosed()
	}
}
func (ch *Channel) Close() {
	ch.Logger().Info("Channel.Close called.")
	var connections []*Connection
	var channelClosed bool

	func() {
		ch.mutable.Lock()
		defer ch.mutable.Unlock()

		if ch.mutable.state == ChannelClosed {
			ch.Logger().Info("Channel already closed, skipping additional Close() calls")
			return
		}

		if ch.mutable.l != nil {
			ch.mutable.l.Close()
		}

		// Stop the idle connections timer.
		ch.mutable.idleSweep.Stop()

		ch.mutable.state = ChannelStartClose
		if len(ch.mutable.conns) == 0 {
			ch.mutable.state = ChannelClosed
			channelClosed = true
		}
		for _, c := range ch.mutable.conns {
			connections = append(connections, c)
		}
	}()

	for _, c := range connections {
		c.close(LogField{"reason", "channel closing"})
	}

	if channelClosed {
		ch.onClosed()
	}
}
// Close starts a graceful Close for the channel. This does not happen immediately:
// 1. This call closes the Listener and starts closing connections.
// 2. When all incoming connections are drained, the connection blocks new outgoing calls.
// 3. When all connections are drained, the channel's state is updated to Closed.