MCPcopy Index your code
hub / github.com/cortexlabs/cortex / Run

Function Run

pkg/lib/parallel/parallel.go:26–58  ·  view source on GitHub ↗

Alternative: https://golang.org/pkg/sync/#WaitGroup (with error channel) Alternative: https://godoc.org/golang.org/x/sync/errgroup

(fn func() error, fns ...func() error)

Source from the content-addressed store, hash-verified

24// Alternative: https://godoc.org/golang.org/x/sync/errgroup
25
26func Run(fn func() error, fns ...func() error) []error {
27 allFns := append(fns, fn)
28
29 errChannels := make([]chan error, len(allFns))
30 for i := range errChannels {
31 errChannels[i] = make(chan error)
32 }
33
34 for i := range allFns {
35 fn := allFns[i]
36 errChannel := errChannels[i]
37
38 if fn == nil {
39 errChannel <- nil
40 continue
41 }
42
43 go func() {
44 defer func() {
45 if r := recover(); r != nil {
46 errChannel <- errors.CastRecoverError(r)
47 }
48 }()
49 errChannel <- fn()
50 }()
51 }
52
53 errors := make([]error, len(allFns))
54 for i := range allFns {
55 errors[i] = <-errChannels[i]
56 }
57 return errors
58}
59
60func RunFirstErr(fn func() error, fns ...func() error) error {
61 errs := Run(fn, fns...)

Callers 2

CloseFunction · 0.92
RunFirstErrFunction · 0.70

Calls 1

CastRecoverErrorFunction · 0.92

Tested by

no test coverage detected