Parcourir la Source

Fix spawning of the error reporting goroutine

It has to be spawned *before* we run the main loop, because otherwise if
we had too many errors this would have blocked them.  (Where too many is
`2 * config.concurrency`.  After *all* fetching goroutines would be
blocked and could never resume because the `errors` channel is buffered
as well.  That shouldn't happen now.)
Lucas Stadler 10 ans auparavant
Parent
commit
8abecc94c2
1 fichiers modifiés avec 8 ajouts et 8 suppressions
  1. 8 8
      go/stars/stars.go

+ 8 - 8
go/stars/stars.go

@ -36,7 +36,15 @@ func main() {
36 36
	sem := make(chan bool, config.concurrency)
37 37
	var wg sync.WaitGroup
38 38
39
	hadErrors := false
39 40
	errors := make(chan error, config.concurrency)
41
	go func() {
42
		for err := range errors {
43
			hadErrors = true
44
			fmt.Fprintln(os.Stderr, "Error:", err)
45
		}
46
	}()
47
40 48
	wg.Add(len(stars))
41 49
	for _, info := range stars {
42 50
		info := info
@ -54,14 +62,6 @@ func main() {
54 62
		}()
55 63
	}
56 64
57
	hadErrors := false
58
	go func() {
59
		for err := range errors {
60
			hadErrors = true
61
			fmt.Fprintln(os.Stderr, "Error:", err)
62
		}
63
	}()
64
65 65
	wg.Wait()
66 66
	close(errors)
67 67