package main import ( "fmt" "sync" "time" ) type Rate struct { RPM int mu sync.Mutex } func main() { r := Rate{RPM: 10} for i := 0; i < 10; i++ { go func(j int) { r.RateLimit() fmt.Println("Rate limiting") }(i) } time.Sleep(time.Minute) } func (r *Rate) RateLimit() { // Lock for the fraction of a minute based on RPM r.mu.Lock() // Unlock after the fraction of a minute time.Sleep(time.Minute / time.Duration(r.RPM)) r.mu.Unlock() }