first commit

This commit is contained in:
Matthew-js
2025-10-03 14:32:45 +07:00
commit 40c37b5880
9 changed files with 444 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
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
}