MCPcopy Create free account
hub / github.com/git-bug/git-bug / TryGo

Method TryGo

util/multierr/errwaitgroup.go:76–97  ·  view source on GitHub ↗

TryGo calls the given function in a new goroutine only if the number of active goroutines in the group is currently below the configured limit. The return value reports whether the goroutine was started.

(f func() error)

Source from the content-addressed store, hash-verified

74//
75// The return value reports whether the goroutine was started.
76func (g *ErrWaitGroup) TryGo(f func() error) bool {
77 if g.sem != nil {
78 select {
79 case g.sem <- token{}:
80 // Note: this allows barging iff channels in general allow barging.
81 default:
82 return false
83 }
84 }
85
86 g.wg.Add(1)
87 go func() {
88 defer g.done()
89
90 if err := f(); err != nil {
91 g.mu.Lock()
92 err = Join(g.err, err)
93 g.mu.Unlock()
94 }
95 }()
96 return true
97}
98
99// SetLimit limits the number of active goroutines in this group to at most n.
100// A negative value indicates no limit.

Callers

nothing calls this directly

Calls 4

doneMethod · 0.95
JoinFunction · 0.85
AddMethod · 0.80
LockMethod · 0.65

Tested by

no test coverage detected