After first c.doneCh <-true is send, the select will immediate run default flow. The Receive will get io.EOF again, but at that time, the listenWrite is exit because of c.donCh. The c.doneCh is not buffered, so it will be blocked for ever.
The simple fix is add time.Sleep(xxx) after the c.doneCh <-true. (Any way it is not a good fix.)
Simple run the demo, it works, but the flow has problem.
func (c *Client) listenRead() the api is never exited, always blocked on the c.doneCh on the second time
After first c.doneCh <-true is send, the select will immediate run default flow. The Receive will get io.EOF again, but at that time, the listenWrite is exit because of c.donCh. The c.doneCh is not buffered, so it will be blocked for ever.
The simple fix is add time.Sleep(xxx) after the c.doneCh <-true. (Any way it is not a good fix.)