Skip to content

Conversation

corentone
Copy link

Are we correctly waiting for result processing?

Since we only wait on wg.Wait() it could return before all the println have happened since we dont wait for that.
We should somehow also have a mechanism to wait for all the messages to have been processed. Im still trying to think what would be the cleanest solution.

@@ -160,6 +160,7 @@ func main() {
messages <- 3
}()
go func() {
// we should wait for completion here?
Copy link
Author

Choose a reason for hiding this comment

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

obivously dont merge me :)

@corentone
Copy link
Author

corentone commented Oct 20, 2020

Tagging you per the article; sorry its super old, I was looking for a nice pattern and found your blog but Im thinking there is a potential issue :)
@nathanleclaire

The playground that shows it:
https://play.golang.com/p/Lh2bQcJedso

@corentone corentone changed the title Golang goroutine Golang goroutine result issue Oct 20, 2020
@corentone
Copy link
Author

I found a solution with just adding another wait group;
https://play.golang.com/p/4-89F4fPWTc

For your article it may be easier to just not deal with the result and do the printing in the work goroutine

@nathanleclaire nathanleclaire force-pushed the master branch 4 times, most recently from 0b0cc4b to 06d55fa Compare June 24, 2024 16:16
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.

1 participant