MCPcopy Create free account
hub / github.com/OpenSN-Library/OpenSN-Library / ForEachWithThreadPool

Function ForEachWithThreadPool

daemon/utils/decorator.go:62–75  ·  view source on GitHub ↗

pass by value, cannot have side-effect

(callable func(v T), array []T, maxRoutine int)

Source from the content-addressed store, hash-verified

60
61// pass by value, cannot have side-effect
62func ForEachWithThreadPool[T any](callable func(v T), array []T, maxRoutine int) *sync.WaitGroup {
63 chanBuf := make(chan bool, maxRoutine)
64 wg := new(sync.WaitGroup)
65 for _, v := range array {
66 chanBuf <- true
67 wg.Add(1)
68 go func(v T) {
69 callable(v)
70 <-chanBuf
71 wg.Done()
72 }(v)
73 }
74 return wg
75}
76
77// Pass by value, cannot have side-effect
78func ForEachUtilAllComplete[T any](callable func(v T) (bool, error), array []T) error {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected