Skip to content

Fix reusing the url variable in concurrency tutorial#825

Open
EduKav1813 wants to merge 2 commits intoquii:mainfrom
EduKav1813:fix-goroutine-variable-reuse
Open

Fix reusing the url variable in concurrency tutorial#825
EduKav1813 wants to merge 2 commits intoquii:mainfrom
EduKav1813:fix-goroutine-variable-reuse

Conversation

@EduKav1813
Copy link
Copy Markdown

The current version's tests didn't work for me at the end of the section. I propose a fix.

The exact wording or maybe even the implementation may be improved/modified, but I think this should be covered in the tutorial.

Comment thread concurrency/v3/check_websites.go Outdated
resultChannel := make(chan result)

for _, url := range urls {
u := url
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It be better to add a Parameter in the function instead declaring the variable . Like

go func(url string) {
			resultChannel <- result{url, wc(url)}
		}(url)

Signed-off-by: Eduard Kaverinskyi <eduard.kaverinskyi@gmail.com>
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