Pārlūkot izejas kodu

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 gadi atpakaļ
vecāks
revīzija
8abecc94c2
1 mainītis faili ar 8 papildinājumiem un 8 dzēšanām
  1. 8 8
      go/stars/stars.go

+ 8 - 8
go/stars/stars.go

36
	sem := make(chan bool, config.concurrency)
36
	sem := make(chan bool, config.concurrency)
37
	var wg sync.WaitGroup
37
	var wg sync.WaitGroup
38
38
39
	hadErrors := false
39
	errors := make(chan error, config.concurrency)
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
	wg.Add(len(stars))
48
	wg.Add(len(stars))
41
	for _, info := range stars {
49
	for _, info := range stars {
42
		info := info
50
		info := info
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
	wg.Wait()
65
	wg.Wait()
66
	close(errors)
66
	close(errors)
67
67