Go Logo

Go: Throttle function

import ( ⏎
	"time"
)

func Throttle(fn func(), interval time.Duration) func() {
	var lastExecuted time.Time

	return func() {
		now := time.Now()
		if now.Sub(lastExecuted) >= interval {
			lastExecuted = now
			fn()
		}
	}
}
Accuracy
100 %
0 Mistakes
CPM
0
Average: 0 CPM
Time
0.000 s
Personal best: -.--- s