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

Added example of reading from closed channel #498

Merged
merged 2 commits into from
Nov 30, 2023
Merged

Added example of reading from closed channel #498

merged 2 commits into from
Nov 30, 2023

Conversation

zhuboris
Copy link
Contributor

@zhuboris zhuboris commented Nov 28, 2023

@zhuboris
Copy link
Contributor Author

zhuboris commented Nov 28, 2023

I've decided to not include example of writing to a closed channel because panic was never explained in previous examples.

// It is possible to read from an empty closed channel,
// but instead of waiting for a message, we will
// immediately receive a zero value of the channel's type.
j := <-jobs
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it'd be useful to demonstrate the 2-return form of <- here, because it's aimed exactly at this use case


# The idea of closed channels leads naturally to our next
# example: `range` over channels.
# Be sure that channel is not closed when you read
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's leave this out, keeping the original text.
gobyexample tries not to be too tutorial-y describing all the possible edge cases

Also revert too complicated paragraph
@zhuboris
Copy link
Contributor Author

Сommitted the edits with an example of both returned values and revert the changes to the last paragraph

@eliben eliben merged commit 991f893 into mmcgrana:master Nov 30, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants