File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ package checker
2
+
3
+ import (
4
+ "sync"
5
+ )
6
+
7
+ // Worker must be implemented by types that want to use
8
+ // the work pool.
9
+ type Worker interface {
10
+ Do () (bool , error )
11
+ }
12
+
13
+ // Pool provides a pool of goroutines that can execute any Worker
14
+ // tasks that are submitted.
15
+ type Pool struct {
16
+ works chan Worker
17
+ wg sync.WaitGroup
18
+ }
19
+
20
+ // New creates a new work pool.
21
+ func New (maxGoroutines int ) * Pool {
22
+ p := Pool {
23
+ works : make (chan Worker ),
24
+ }
25
+
26
+ p .wg .Add (maxGoroutines )
27
+ for i := 0 ; i < maxGoroutines ; i ++ {
28
+ go func () {
29
+ for w := range p .works {
30
+ w .Do ()
31
+ }
32
+ p .wg .Done ()
33
+ }()
34
+ }
35
+
36
+ return & p
37
+ }
38
+
39
+ // Run submits work to the pool.
40
+ func (p * Pool ) Run (w Worker ) {
41
+ p .works <- w
42
+ }
43
+
44
+ // Shutdown waits for all the goroutines to shutdown.
45
+ func (p * Pool ) Shutdown () {
46
+ close (p .works )
47
+ p .wg .Wait ()
48
+ }
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ module github.com/Hywfred/IPTVlist
2
+
3
+ go 1.17
You can’t perform that action at this time.
0 commit comments