Colly callback not receiving variable from go func

This seems pretty convoluted. It looks like you are using github.com/gocolly/colly. Why is that section in a goroutine exactly? I would first try getting rid of that. It seems as though the collectors are already using goroutines (I am just guessing since they have a Wait function; I didn’t look at the docs to confirm this).

This code looks like it’s missing some stuff (like where are you waiting for wgFR? Where is wgFR even defined?) so off the top of my head one something could be modifying the strings in your outer functions that you might not be anticipating. In the problematic contestCollector.OnHTML callback you are not passing those values to that function so it could be falling prey to something like this:

func main() {
	myAwesomeValue := "awesome"
	wg := sync.WaitGroup{}
	wg.Add(1)
	go func() {
		time.Sleep(time.Millisecond)
		fmt.Println("The value is", myAwesomeValue)
		wg.Done()
	}()
	myAwesomeValue = "not awesome"
	wg.Wait()
}

… which prints The value is not awesome.

1 Like