Skip to content

Commit 80ac847

Browse files
committed
Clarify CloseRead docs
1 parent cc4687b commit 80ac847

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

websocket.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,14 @@ func (c *Conn) reader(ctx context.Context) (MessageType, io.Reader, error) {
386386
return MessageType(h.opcode), r, nil
387387
}
388388

389-
// CloseRead will close the connection if any data message is received from the peer.
390-
// Call this when you are done reading data messages from the connection but will still write
391-
// to it. Since CloseRead is still reading from the connection, it will respond to ping, pong
392-
// and close frames automatically. It will only close the connection on a data frame. The returned
393-
// context will be cancelled when the connection is closed.
389+
// CloseRead will start a goroutine to read from the connection until it is closed or a data message
390+
// is received. If a data message is received, the connection will be closed with StatusPolicyViolation.
391+
// Since CloseRead reads from the connection, it will respond to ping, pong and close frames.
392+
// After calling this method, you cannot read any data messages from the connection.
393+
// The returned context will be cancelled when the connection is closed.
394+
//
395+
// Use this when you do not want to read data messages from the connection anymore but will
396+
// want to write messages to it.
394397
func (c *Conn) CloseRead(ctx context.Context) context.Context {
395398
ctx, cancel := context.WithCancel(ctx)
396399
go func() {

0 commit comments

Comments
 (0)