What happens is that the for loop places the value of elements[i]
in the same element
variable for each iteration, not creating a new one. This means that &element
is always the same address (try printing it before calling the function!)
A simple solution would be to just pass it a pointer to the actual memeber of the slice:
for i := range elements {
go func(element *Element){
fmt.Println("PostStream: ", element.Name)
waiting <- true
}(&elements[i])
}