Jay
273278d322
1. add cron module 2. add pool module 3. add tcgplayer background job 4. add card price model
39 lines
438 B
Go
39 lines
438 B
Go
package pool
|
|
|
|
import "sync"
|
|
|
|
// Pool -
|
|
type Pool struct {
|
|
queue chan bool
|
|
wg *sync.WaitGroup
|
|
}
|
|
|
|
// NewPool -
|
|
func NewPool(size int) *Pool {
|
|
if size < 1 {
|
|
size = 1
|
|
}
|
|
p := &Pool{
|
|
queue: make(chan bool, size),
|
|
wg: &sync.WaitGroup{},
|
|
}
|
|
return p
|
|
}
|
|
|
|
// Add -
|
|
func (p *Pool) Add() {
|
|
p.queue <- true
|
|
p.wg.Add(1)
|
|
}
|
|
|
|
// Done -
|
|
func (p *Pool) Done() {
|
|
<-p.queue
|
|
p.wg.Done()
|
|
}
|
|
|
|
// Wait -
|
|
func (p *Pool) Wait() {
|
|
p.wg.Wait()
|
|
}
|