Without spawning a goroutine, your code gets stuck at the point it starts writing to the channel.
The channel is not buffered, and there is no other goroutine running that reads from it, so the code cannot move on. This also explains why the code runs when you use a buffered channel instead.
I cannot comment on the goroutine version, as the goroutine code you posted contains just an empty for loop. I believe this is not the goroutine you were using—can you please check this part and post the complete goroutine?
rows in the moment it returns. You might want to keep
rows open until the goroutine has read all rows. (The problem does not exist in the non-goroutine version. Here, all rows are written into the channel’s buffer before the
defer statement closes
And when using a goroutine and a non-buffered channel you would need to avoid closing
dev before returning it.
Sorry if only half of what I wrote makes sense, it’s 11pm over here