And another tweak, I noticed that still, under some circumstances, it was possible for some output to get lost, especially when sending the output received into e.g. a slice or a map instead of printing. Adding a done channel, fixes this.
done := make(chan bool) // done channel
go func() {
for m := range outputs {
fmt.Println(m)
}
done <- true // when we're done printing, send true
}()
wg.Wait()
close(outputs)
<-done // block and wait for done
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
And another tweak, I noticed that still, under some circumstances, it was possible for some output to get lost, especially when sending the output received into e.g. a slice or a map instead of printing. Adding a
done
channel, fixes this.