diff --git a/main.go b/main.go index 6e99f82..28caf60 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,6 @@ import ( "os" "path" "strings" - "time" ) var ( @@ -29,8 +28,9 @@ func main() { defer file.Close() c := make(chan string, *worker) + quit := make(chan bool) for i := 0; i < *worker; i++ { - go processFileEntry(c) + go processFileEntry(c, quit) } scanner := bufio.NewScanner(file) @@ -39,14 +39,16 @@ func main() { } close(c) - // Let's wait 10 sec for the last images to download. - time.Sleep(10 * 1e9) + for i := 0; i < *worker; i++ { + <-quit + } } -func processFileEntry(c <-chan string) { +func processFileEntry(c <-chan string, quit chan<- bool) { for str := range c { downloadFile(str) } + quit <- true } func downloadFile(url string) {