2025-10-03 14:32:45 +07:00

33 lines
675 B
Go

package worker
import (
"fmt"
"sync"
"time"
)
// ProsesSertifikasi simulates certification processing for a single user.
func ProsesSertifikasi(userID int) string {
// simulate variable work (sleep)
time.Sleep(time.Millisecond * time.Duration(50+userID%10*20))
return fmt.Sprintf("user-%d: done", userID)
}
// RunSertifikasi starts n goroutines and waits for all to finish.
// Returns results in a slice.
func RunSertifikasi(n int) []string {
var wg sync.WaitGroup
wg.Add(n)
results := make([]string, n)
for i := 0; i < n; i++ {
i := i // capture
go func() {
defer wg.Done()
results[i] = ProsesSertifikasi(i + 1)
}()
}
wg.Wait()
return results
}