Skip to content

Instantly share code, notes, and snippets.

@Allanfs
Created May 3, 2023 01:32
Show Gist options
  • Save Allanfs/5a3570b7acd6ec181700ad00faaf3f2f to your computer and use it in GitHub Desktop.
Save Allanfs/5a3570b7acd6ec181700ad00faaf3f2f to your computer and use it in GitHub Desktop.
Result of channel operations given a channel’s state
Operation Channel state Result
Read nil Block
Open and Not Empty Value
Open and Empty Block
Closed <default value>, false
Write Only Compilation Error
Write nil Block
Open and full Block
Open and Not Full Write Value
Closed panic
Receive Only Compilation Error
close nil panic
Open and Not Empty Closes Channel; reads succeed until channel is drained, then reads produce default value
Open and Empty Closes Channel; reads produces default value
Closed panic
Receive Only Compilation Error

Source: Concurrency in Go by Katherine Cox-Buday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment