Open lihp1603 opened 3 years ago
你好,阅读了一下这个代码,发现 func NewPeer(id string, con transport.WebSocketTransport) Peer { var peer Peer peer.id = id peer.transport = con peer.PeerChans = PeerChans{ OnRequest: make(chan RequestData, 100), OnNotification: make(chan Notification, 100), SendRequest: make(chan SendRequestData, 100), OnClose: make(chan transport.TransportErr, 1), } peer.transcations = make(map[int]*Transcation)
go peer.Run() 这个地方之间开启了一个goroutine return &peer
} 而goroutine的run代码如下: func (peer *Peer) Run() { for { select { case msg := <-peer.transport.OnMsg: peer.handleMessage(msg) case err := <-peer.transport.OnErr: peer.handleErr(err) case err := <-peer.transport.OnClose: peer.handleClose(err) //return ? case data := <-peer.SendRequest: peer.sendRequest(data) } } }
貌似没办法退出这个goroutine?
你好,阅读了一下这个代码,发现 func NewPeer(id string, con transport.WebSocketTransport) Peer { var peer Peer peer.id = id peer.transport = con peer.PeerChans = PeerChans{ OnRequest: make(chan RequestData, 100), OnNotification: make(chan Notification, 100), SendRequest: make(chan SendRequestData, 100), OnClose: make(chan transport.TransportErr, 1), } peer.transcations = make(map[int]*Transcation)
} 而goroutine的run代码如下: func (peer *Peer) Run() { for { select { case msg := <-peer.transport.OnMsg: peer.handleMessage(msg) case err := <-peer.transport.OnErr: peer.handleErr(err) case err := <-peer.transport.OnClose: peer.handleClose(err) //return ? case data := <-peer.SendRequest: peer.sendRequest(data) } } }
貌似没办法退出这个goroutine?