You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: throttle.go
    path of file: ./repos/buildkit/util/throttle
    
    the code of the file until where you have to start completion: package throttle

import (
	"sync"
	"time"
)

// Throttle wra
    
func throttle(d time.Duration, f func(), wait bool) func() {
	var next, running bool
	var mu sync.Mutex
	return func() {
		mu.Lock()
		defer mu.Unlock()

		next = true
		if !running {
			running = true
			go func() {
				for {
					mu.Lock()
					if !next {
						running = false
						mu.Unlock()
						return
					}
					if !wait {
						next = false
					}
					mu.Unlock()

					if wait {
						time.Sleep(d)
						mu.Lock()
						next = false
						mu.Unlock()
						f()
					} else {
						f()
						time.Sleep(d)
					}
				}
			}()
		}
	}
}