some rate limiting

This commit is contained in:
Mark McGranaghan 2012-09-20 00:05:41 -07:00
parent cc8b8cf7a4
commit 8b131ba347
3 changed files with 40 additions and 1 deletions

1
README
View File

@ -42,7 +42,6 @@ gobyexample.com signups
* web app
* serve static files
* mongo
* rate limiting
* time formatting
* typed json parse/unparse
* gzip

View File

@ -0,0 +1,25 @@
package main
import ("time"; "fmt")
func main() {
tick := time.Tick(time.Millisecond * 200)
throttle := make(chan bool, 10)
go func() {
for {
<- tick
select {
case throttle <- true:
default:
}
}
}()
time.Sleep(time.Millisecond * 1000)
for {
<- throttle
go fmt.Println("acting")
}
}
// == todo
// credit http://code.google.com/p/go-wiki/wiki/RateLimiting

15
src/xx-rate-limiting.go Normal file
View File

@ -0,0 +1,15 @@
package main
import ("time"; "fmt")
func main() {
throttle := time.Tick(time.Millisecond * 200)
for {
<- throttle
go fmt.Println("rate-limited action")
}
}
// == todo
// credit http://code.google.com/p/go-wiki/wiki/RateLimiting