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

Use empty struct to protect writing #566

Merged
merged 1 commit into from
Mar 19, 2020

Conversation

ferhatelmas
Copy link
Contributor

Summary of Changes
Use empty struct instead of boolean for write protection
on connection.

Motivation

  1. Using empty struct for signaling is more idiomatic
    compared to booleans because users might wonder
    what happens on false or true. Empty struct removes
    this problem.

  2. There is also a side benefit of occupying less memory
    but it should be negligible in this case.

Using empty struct for signaling is more idiomatic
compared to booleans because users might wonder
what happens on false or true. Empty struct removes
this problem.

There is also a side benefit of occupying less memory
but it should be negligible in this case.
@elithrar elithrar self-assigned this Mar 19, 2020
@@ -244,8 +244,8 @@ type Conn struct {
subprotocol string

// Write fields
mu chan bool // used as mutex to protect write to conn
writeBuf []byte // frame is constructed in this buffer.
mu chan struct{} // used as mutex to protect write to conn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@elithrar elithrar merged commit 015e196 into gorilla:master Mar 19, 2020
@ferhatelmas ferhatelmas deleted the empty-struct-for-write branch November 25, 2020 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants