-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (40 loc) · 1.08 KB
/
main.go
File metadata and controls
48 lines (40 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"fmt"
"sync/atomic"
workerpool "github.com/abcxyz/pkg/workerpool"
)
/*
Output:
kevya@kevya-but-large:~/gitrepos/merge-queue-testing$ go run main.go
Success Count: 99924
kevya@kevya-but-large:~/gitrepos/merge-queue-testing$ go run main.go
Success Count: 99910
kevya@kevya-but-large:~/gitrepos/merge-queue-testing$ go run main.go
Success Count: 99905
kevya@kevya-but-large:~/gitrepos/merge-queue-testing$ go run main.go
Success Count: 99928
kevya@kevya-but-large:~/gitrepos/merge-queue-testing$ go run main.go
*/
func main() {
ctx := context.Background()
pool := workerpool.New[*workerpool.Void](&workerpool.Config{
Concurrency: int64(10),
StopOnError: false,
})
successCount := atomic.Int64{}
for i := 0; i < 99999; i++ {
if err := pool.Do(ctx, func() (*workerpool.Void, error) {
successCount.Store(successCount.Add(1))
return nil, nil
}); err != nil {
fmt.Printf("pool worker: %s", err)
}
}
_, err := pool.Done(ctx)
fmt.Println("Success Count: ", successCount.Load())
if err != nil {
fmt.Printf("pool error: %s", err)
}
}