first version

This commit is contained in:
Jay
2019-05-15 18:09:36 +08:00
commit 1275619fa0
10 changed files with 365 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
package pool
import "sync"
// Pool -
type Pool struct {
q chan bool
wg *sync.WaitGroup
}
// NewPool -
func NewPool(size int) *Pool {
if size < 1 {
size = 1
}
p := &Pool{
q: make(chan bool, size),
wg: &sync.WaitGroup{},
}
return p
}
// Add new queue work
func (p *Pool) Add() {
p.q <- true
p.wg.Add(1)
}
// Done finish work
func (p *Pool) Done() {
<-p.q
p.wg.Done()
}
// Wait -
func (p *Pool) Wait() {
p.wg.Wait()
}