Commit 5c23a1f 1 parent 0be714a commit 5c23a1f Copy full SHA for 5c23a1f
File tree 1 file changed +61
-0
lines changed
1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ # workerpool
2
+
3
+ Concurrency limiting goroutine pool.
4
+
5
+ ## Install
6
+
7
+ ```
8
+ go get -v github.com/neoql/workerpool
9
+ ```
10
+
11
+ ## Example
12
+
13
+ ``` go
14
+ package main
15
+
16
+ import (
17
+ " fmt"
18
+ " time"
19
+ " sync"
20
+
21
+ " github.com/neoql/workerpool"
22
+ )
23
+
24
+ func main () {
25
+ var wg sync.WaitGroup
26
+
27
+ fn := func (argv workerpool.Argv ) {
28
+ no := argv.(int )
29
+ fmt.Printf (" fn-%d enter...\n " , no)
30
+ time.Sleep (time.Second *3 )
31
+ fmt.Printf (" fn-%d exit.\n " , no)
32
+ wg.Done ()
33
+ }
34
+
35
+ pool := workerpool.New (2 , time.Second *1 )
36
+
37
+ wg.Add (3 )
38
+ for i := 0 ; i < 3 ; i++ {
39
+ if !pool.Spawn (fn, i) {
40
+ fmt.Printf (" launch fn-%d failed, WorkerPool is full" , i)
41
+ fmt.Println (" Waiting for an empty position" )
42
+ pool.WaitSpawn (fn, i)
43
+ }
44
+ }
45
+
46
+ wg.Wait ()
47
+ }
48
+ ```
49
+ ```
50
+ fn-0 enter...
51
+ fn-1 enter...
52
+ launch fn-2 failed, WorkerPool is fullWaiting for an empty position
53
+ fn-1 exit.
54
+ fn-0 exit.
55
+ fn-2 enter...
56
+ fn-2 exit.
57
+ ```
58
+
59
+ ## License
60
+
61
+ MIT, read more [ here] ( ./LICENSE ) .
You can’t perform that action at this time.
0 commit comments