🚨 Add some tooling/ linting
This commit is contained in:
parent
86842326fb
commit
dc577bcb9c
5 changed files with 120 additions and 7 deletions
|
|
@ -131,6 +131,12 @@ func (g *Group) TryGo(f func() error) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
type ErrgroupLimitError struct{ Size int }
|
||||
|
||||
func (egerr *ErrgroupLimitError) Error() string {
|
||||
return fmt.Sprintf("errgroup: modify limit while %v goroutines in the group are still active", egerr.Size)
|
||||
}
|
||||
|
||||
// SetLimit limits the number of active goroutines in this group to at most n.
|
||||
// A negative value indicates no limit.
|
||||
// A limit of zero will prevent any new goroutines from being added.
|
||||
|
|
@ -145,7 +151,8 @@ func (g *Group) SetLimit(n int) {
|
|||
return
|
||||
}
|
||||
if len(g.sem) != 0 {
|
||||
panic(fmt.Errorf("errgroup: modify limit while %v goroutines in the group are still active", len(g.sem)))
|
||||
var err error = &ErrgroupLimitError{len(g.sem)}
|
||||
panic(err)
|
||||
}
|
||||
g.sem = make(chan token, n)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue