Resolving deadlock error

https://play.golang.org/p/AvoTqIJeMD8
trying to get status codes from different sites concurrently, but getting a deadlock error. not sure what the issue is

@JustinObanor, I added a fmt.Printf before the loop and see the first v in sites is empty. That means you’re adding 6 to the wait group and calling Done only 5 times. I recommend this inatead: https://play.golang.org/p/l9ut4uQ6W1L

1 Like

You can also filter out empty strings in your slice before iterating, like this https://play.golang.org/p/RcTQomu2j7d (1)

It’s still recommended to add to the WaitGroup as skillian does.

(1) For reasons unknown my example doesn’t work on the playgroup but works locally with go version go1.14 windows/amd64.

1 Like

Thanks. It doesn’t work on playground because all internet requests are banned there. It works locally as you said

@skillian @Unique also i’d say its better to use sites := strings.Fields(b.String()) like here https://play.golang.org/p/uoPsczEUXon
It throws a nasty error in playground, but all’s good on local IDE

Didn’t know strings.Fields(string). Nice.

1 Like