Skip to content

vcraescu/go-ratelimit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rate limiter

Example

package main

import (
	"fmt"
	"github.com/vcraescu/go-ratelimit"
	"log"
	"time"
)

func worker(i int) {
	fmt.Printf("worker: %d\n", i)
}

func main() {
	limiter := ratelimit.NewLimiter(10, ratelimit.WithPer(time.Second))

	for i := 0; i < 50; i++ {
		i := i

		limiter.Run(func() {
			worker(i)
		})
	}

	if err := limiter.Wait(); err != nil {
		log.Fatalln(err)
	}
}

About

Go blocking leaky-bucket function rate limit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published