mirror of
https://github.com/Luzifer/update-gotools.git
synced 2024-12-22 21:01:20 +00:00
28 lines
330 B
Go
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()
|
|
}
|