I have a loop, for each iteration I have a new channel source, that I should handle. Ok, it's better to show my code. I have list of files, each file I want to tail (like tail -f). I am using github.com/ActiveState/tail
package.
for _, tailFile := range files {
t, _ := tail.TailFile(tailFile, c)
// Goroutine per tailing file
go func() {
for line := range t.Lines { // t.Lines is a channel
// Do some magic here
}
}()
}
I can have thousands of files and I want to run my tail in parallel. As you see my program will have thousands of goroutines. Can this loop be changed to channels, with only 1 goroutine?