1
0
Fork 0
mirror of https://github.com/Luzifer/update-gotools.git synced 2024-10-18 07:04:20 +00:00
update-gotools/limiter.go
2018-02-20 21:31:47 +01:00

28 lines
330 B
Go

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()
}