向桶里面放入令牌 这个用管道吧 线程安全 var capacity = 100 var tokenBucket = make(chan struct{}, capacity) func main(){ var fillInterval =time.Second fillToken := func() { thicker :=time.NewTicker(fillInterval) for { select{ case <-thicker.C: tokenBucket <- struct{}{} fmt.Println("11111111") default: fmt.Println("current number of token is",len(tokenBucket),time.Now()) } } } go fillToken() //time.Sleep(time.Hour) }
从桶中取出令牌