Re:Data Race Patterns in Go
by mmarq on Saturday June 11, 2022 @03:41AM
(#31702718)
My (rather horrid) pattern to address this problem is to wrap the goroutine in a function that returns a channel receiver. When the goroutine ends it sends something to the channel and whatever called it can await the result or completion using the receiver.
[ Parent
| on HN ]
Re:Data Race Patterns in Go
by randomswede on Monday June 13, 2022 @02:41AM
(#31722025)
I have, on occasion, used a similar pattern, but instead of sending something, I simply close the channel (usually with a "defer close(c)" at the beginning of the function/closure that encompasses the main code of the goroutine's work).
That way, if I end up having multiple waiters, they will all be able to proceed.