MCPcopy
hub / github.com/betty200744/ultimate-go / Do

Function Do

LearnConcurrency/goroutines/goroutine_error_handling.go:26–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24}
25
26func Do() {
27 resCh := make(chan Res)
28 for i := 1; i < 9; i++ {
29 go func(i int, resCh chan Res) {
30 result, err := doExpensiveStuff(i)
31 resCh <- Res{result, err}
32 }(i, resCh)
33 }
34
35 for i := 1; i < 9; i++ {
36 r := <-resCh
37 if r.Err != nil {
38 log.Fatal(r.Err)
39 } else {
40 fmt.Println(r)
41 }
42 }
43
44}
45
46func main() {
47 rand.Seed(time.Now().UnixNano())

Callers 1

mainFunction · 0.85

Calls 1

doExpensiveStuffFunction · 0.85

Tested by

no test coverage detected