Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: clarify the semantics of concurrent Read calls #136

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func (s *Stream) StreamID() uint32 {
return s.id
}

// Read is used to read from the stream
// Read is used to read from the stream. It is safe to call Write, Read, and/or
// Close concurrently but Stream provides no guarantees that concurrent Reads
// will receive data in response to Writes made from the same goroutine.
func (s *Stream) Read(b []byte) (n int, err error) {
defer asyncNotify(s.recvNotifyCh)
START:
Expand Down Expand Up @@ -158,7 +160,9 @@ WAIT:
goto START
}

// Write is used to write to the stream
// Write is used to write to the stream. It is safe to call Write, Read, and/or
// Close concurrently but Stream provides no guarantees that concurrent Reads
// will receive data in response to Writes made from the same goroutine.
func (s *Stream) Write(b []byte) (n int, err error) {
s.sendLock.Lock()
defer s.sendLock.Unlock()
Expand Down Expand Up @@ -320,7 +324,8 @@ func (s *Stream) sendClose() error {
return nil
}

// Close is used to close the stream
// Close is used to close the stream. It is safe to call Write, Read, and/or
// Close concurrently.
func (s *Stream) Close() error {
closeStream := false
s.stateLock.Lock()
Expand Down
Loading