Can't get information into channel

https://play.golang.org/p/bDHuJIyMc_V

This is the link to the code I have written to parse over a document and find the lines with information missing. When I move the info into msgs channel, it is not working. Please let me know how to correct this.

1 Like

Please, describe what is actual behaviour of the task, what it’s expected behaviour and what are you trying to do. It’s hardly to test it without sample of .csv file.

1 Like

I made some refactoring on your code, there were a few problems. But I will just point two of them that causes the issue that you mentioned.

You are calling two goroutines:

wg.Add(1)## make it wg.Add(2) to wait for two goroutines
go consume(whichones)
go produce("PeopleEx1.csv", &wg)

Second, when you are done with your producer, you need to stop consumer too.
(Take a look at https://golang.org/pkg/context/)
To do that; you can call the close(msgs) channel, and change your receiver channel as below:

select {
		case a, ok := <-msgs:
			{
				if !ok {
					fmt.Println("INFO: exiting from consume")
					return
				}
				d := missing(a)
				if d == false {
					whichones = append(whichones, counter)
				}
			}}

here is the refactored code:
https://play.golang.org/p/-H6vDiMne3D

4 Likes

Thank you so much this worked perfectly!

1 Like