Skip to content

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
// 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
2 participants