Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a collection of goroutines like errgroup.Group.
Example ¶
Original example is https://pkg.go.dev/golang.org/x/sync/errgroup#example-Group-JustErrors
package main
import (
"fmt"
"net/http"
"github.com/k1LoW/concgroup"
)
func main() {
cg := new(concgroup.Group)
var urlgroups = map[string][]string{
"go": {
"https://go.dev/",
"https://go.dev/dl/",
},
"google": {
"http://www.google.com/",
},
}
for key, ug := range urlgroups {
key := key
for _, url := range ug {
url := url // https://golang.org/doc/faq#closures_and_goroutines
cg.Go(key, func() error {
// Fetch URL sequentially by key
resp, err := http.Get(url)
if err == nil {
resp.Body.Close()
}
return err
})
}
}
// Wait for all HTTP fetches to complete.
if err := cg.Wait(); err == nil {
fmt.Println("Successfully fetched all URLs.")
}
}
func WithContext ¶
WithContext returns a new Group and an associated Context like errgroup.Group.
func (*Group) GoMulti ¶ added in v1.1.0
GoMulti calls the given function in a new goroutine like errgroup.Group with multiple key locks.
func (*Group) SetLimit ¶
SetLimit limits the number of active goroutines in this group to at most n like errgroup.Group.
func (*Group) TryGo ¶
TryGo calls the given function only when the number of active goroutines is currently below the configured limit like errgroup.Group with key.
func (*Group) TryGoMulti ¶ added in v1.1.0
TryGoMulti calls the given function only when the number of active goroutines is currently below the configured limit like errgroup.Group with multiple key locks.