7 ms·
Small bug irrelevant to the main point of the article: The very last golang example has a leak. If the timeout does occur, main will exit after a timeout and th
by simpleglider 13y ago
Small bug irrelevant to the main point of the article:
The very last golang example has a leak. If the timeout does occur, main will exit after a timeout and the spawned go routine will hang on the channel push.
I think the easiest fix is to make the channel buffered.
"make(chan string)" => "make(chan string, 1)"
Not sure if there is a more idiomatic golang way to accomplish this.
- kisielk 13y agoOnce main exits the program does as well, so all other goroutines will be terminated.
- simpleglider 13y agoTrue. Leaks don't matter for programs that exit immediately. I was pointing it out because it is often relevant when using the timeout pattern.