I thougt If the waitgroup gets below 0 there should be a Panic.
I understand that the goroutine is canceled. So maybe the defer Statement is Not executed.
But why is there No warning at the end of Main that some goroutines Had to be canceled?
Thx
Yours
Stephan
Jan Mercl
unread,
May 14, 2020, 2:32:51 AM5/14/20
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sperber...@googlemail.com, golang-nuts
wg.Wait at line 18 does not wait for anything and the program exists
before the goroutine executing func worker even starts. IOW, wg.Done
at line 10 is not executed hence no panic.
Jake Montgomery
unread,
May 14, 2020, 12:17:30 PM5/14/20
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
To clarify what Jan said, a Go program exits when main() exits. Since `wg` has a count of 0, the call to wg.Wait() on like 18 doe not wat, so the program exits before your goroutine even has time to run. With slight modification, it does panic as expected: https://play.golang.org/p/ivcfhsu1N9K