1
0
Fork 0
mirror of https://github.com/Luzifer/update-gotools.git synced 2024-10-18 15:14:19 +00:00
update-gotools/limiter.go

29 lines
330 B
Go
Raw Normal View History

2018-02-20 20:31:47 +00:00
package main
import "sync"
type limiter struct {
l chan struct{}
w sync.WaitGroup
}
func newLimiter(max int) *limiter {
return &limiter{
l: make(chan struct{}, max),
}
}
func (l *limiter) Add() {
l.l <- struct{}{}
l.w.Add(1)
}
func (l *limiter) Done() {
<-l.l
l.w.Done()
}
func (l *limiter) Wait() {
l.w.Wait()
}