mattermost-community-enterp.../vendor/github.com/redis/rueidis/internal/util/parallel.go
Claude ec1f89217a Merge: Complete Mattermost Server with Community Enterprise
Full Mattermost server source with integrated Community Enterprise features.
Includes vendor directory for offline/air-gapped builds.

Structure:
- enterprise-impl/: Enterprise feature implementations
- enterprise-community/: Init files that register implementations
- enterprise/: Bridge imports (community_imports.go)
- vendor/: All dependencies for offline builds

Build (online):
  go build ./cmd/mattermost

Build (offline/air-gapped):
  go build -mod=vendor ./cmd/mattermost

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-17 23:59:07 +09:00

46 lines
814 B
Go

package util
import (
"sync"
)
func ParallelKeys[K comparable, V any](maxp int, p map[K]V, fn func(k K)) {
ch := make(chan K, len(p))
for k := range p {
ch <- k
}
closeThenParallel(maxp, ch, fn)
}
func ParallelVals[K comparable, V any](maxp int, p map[K]V, fn func(k V)) {
ch := make(chan V, len(p))
for _, v := range p {
ch <- v
}
closeThenParallel(maxp, ch, fn)
}
func worker[V any](wg *sync.WaitGroup, ch chan V, fn func(k V)) {
for v := range ch {
fn(v)
}
wg.Done()
}
func closeThenParallel[V any](maxp int, ch chan V, fn func(k V)) {
close(ch)
concurrency := len(ch)
if concurrency > maxp {
concurrency = maxp
}
var wg sync.WaitGroup
wg.Add(concurrency)
for i := 1; i < concurrency; i++ {
go worker(&wg, ch, fn)
}
if concurrency > 0 {
worker(&wg, ch, fn)
}
wg.Wait()
}