Skip to content

Commit 6de8d8e

Browse files
committed
adjust source location and try to add some scripts about IPTV source check
1 parent 2addda0 commit 6de8d8e

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

checker/pool.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/Hywfred/IPTVlist
2+
3+
go 1.17

0 commit comments

Comments
 (0)