-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: Added go for routines - Correct doc #571
Open
hudem1
wants to merge
1
commit into
mmcgrana:master
Choose a base branch
from
hudem1:fix/examples
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,9 @@ func main() { | |
var s []string | ||
fmt.Println("uninit:", s, s == nil, len(s) == 0) | ||
|
||
// To create an empty slice with non-zero length, use | ||
// To create a slice with non-zero length, use | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is ok, changing "an empty" to "a", but the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes okayy sure! |
||
// the builtin `make`. Here we make a slice of | ||
// `string`s of length `3` (initially zero-valued). | ||
// `string`s of length `3` (initially zero-valued, ie ""). | ||
// By default a new slice's capacity is equal to its | ||
// length; if we know the slice is going to grow ahead | ||
// of time, it's possible to pass a capacity explicitly | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the channels are buffered, the
go
statements aren't necessary here. They won't hurt, but one may wonder if they're needed.I suppose the channels could be made unbuffered and
go
keywords added, this would have a similar effectThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes okay, it's just that I thought without
go
the code just becomes synchronous, so we're guaranteed thatping
will happen beforepong
before the main exiting. But with addinggo
, it's the channels directions, especially receiving from channels that enforces the order of execution (ping
thenpong
then the main routine exiting). So, I thought addinggo
really made clear that thanks to blocking when trying to receive from channels, we get the correct order of execution.But I guess here the example was mostly about the fact that we can pass specific channel directions as function parameters. So, the underlying example matters a bit less.
Let me know what you'd prefer, I can remove the
go
if you think it's better this way, no worries :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah let's just remove the
go
s